n, m = map(int,input().split())
lst = []
for i in range(m):
    lst.append(list(map(int,input().split())))

min = lst[0][0]
max = lst[0][1]
for v in lst:
    if v[0] > min:
        min = v[0]
    if v[1] < max:
        max = v[1]
if min <= max:
    print(max-min + 1)
elif min > max:
    print(0) n, m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m lst = [] lst [] for i in range(m):
    lst.append(list(map(int,input().split()))) i range(m) range m lst.append(list(map(int,input().split()))) lst.append lst append list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split min = lst[0][0] min lst[0][0] [0] lst 0 0 max = lst[0][1] max lst[0][1] [0] lst 0 1 for v in lst:
    if v[0] > min:
        min = v[0]
    if v[1] < max:
        max = v[1] v lst if v[0] > min:
        min = v[0]
     v[0] > min v[0] v 0 min min = v[0] min v[0] v 0 if v[1] < max:
        max = v[1] v[1] < max v[1] v 1 max max = v[1] max v[1] v 1 if min <= max:
    print(max-min + 1)
elif min > max:
    print(0) min <= max min max print(max-min + 1) print max-min + 1 max-min max min 1 elif min > max:
    print(0) min > max min max print(0) print 0 min = v[0] v[0] min max = lst[0][1] lst[0][1] max max = v[1] v[1] max min = lst[0][0] lst[0][0] min n, m = map(int,input().split()) map(int,input().split()) n m = map(int,input().split()) map(int,input().split()) m lst = [] [] lst
n, m = map(int,input().split())
lst = []
for i in range(m):
    lst.append(list(map(int,input().split())))

min = lst[0][0]
max = lst[0][1]
for v in lst:
    if v[0] > min:
        min = v[0]
    if v[1] < max:
        max = v[1]
if min <= max:
    print(max-min + 1)
elif min > max:
    print(0)
