import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m = map(int, input().split())
    L, R = 1, n
    for _ in range(m):
        l, m = map(int, input().split())
        if l > L: L = l
        if m < R: R = m
    print(max(0, R-L+1))
    
if __name__ == '__main__':
    main() import sys sys input = lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip def main():
    n, m = map(int, input().split())
    L, R = 1, n
    for _ in range(m):
        l, m = map(int, input().split())
        if l > L: L = l
        if m < R: R = m
    print(max(0, R-L+1))
     main n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m L, R = 1, n L 1 R n for _ in range(m):
        l, m = map(int, input().split())
        if l > L: L = l
        if m < R: R = m
     _ range(m) range m l, m = map(int, input().split()) l map(int, input().split()) map int input().split() ().split () input split m if l > L: L = l
         l > L l L if m < R: R = m
     m < R m R print(max(0, R-L+1)) print max(0, R-L+1) max 0 R-L+1 R-L R L 1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n, m = map(int, input().split())
    L, R = 1, n
    for _ in range(m):
        l, m = map(int, input().split())
        if l > L: L = l
        if m < R: R = m
    print(max(0, R-L+1))
     def main():
    n, m = map(int, input().split())
    L, R = 1, n
    for _ in range(m):
        l, m = map(int, input().split())
        if l > L: L = l
        if m < R: R = m
    print(max(0, R-L+1))
     main input = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m = map(int, input().split())
    L, R = 1, n
    for _ in range(m):
        l, m = map(int, input().split())
        if l > L: L = l
        if m < R: R = m
    print(max(0, R-L+1))
    
if __name__ == '__main__':
    main()