n, m = list(map(int, input().split()))

list = [list(map(int, input().split())) for x in range(m)]

ans = [1]*n

s = 0
m = n

for i in list:
    if i[0] > s:
        s = i[0]
    if i[1] < m:
        m = i[1]
if m>=s:
    print(m-s+1)
else:
    print(0) n, m = list(map(int, input().split())) n list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split m list(map(int, input().split())) for x in range(m) for x in range(m) x range(m) range m for x in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split list = [list(map(int, input().split())) for x in range(m)] list [list(map(int, input().split())) for x in range(m)] ans = [1]*n ans [1]*n [1] 1 n s = 0 s 0 m = n m n for i in list:
    if i[0] > s:
        s = i[0]
    if i[1] < m:
        m = i[1] i list if i[0] > s:
        s = i[0]
     i[0] > s i[0] i 0 s s = i[0] s i[0] i 0 if i[1] < m:
        m = i[1] i[1] < m i[1] i 1 m m = i[1] m i[1] i 1 if m>=s:
    print(m-s+1)
else:
    print(0) m>=s m s print(m-s+1) print m-s+1 m-s m s 1 print(0) print 0 s = 0 0 s s = i[0] i[0] s n, m = list(map(int, input().split())) list(map(int, input().split())) n m = list(map(int, input().split())) list(map(int, input().split())) m ans = [1]*n [1]*n ans m = n n m m = i[1] i[1] m list = [list(map(int, input().split())) for x in range(m)] [list(map(int, input().split())) for x in range(m)] list
n, m = list(map(int, input().split()))

list = [list(map(int, input().split())) for x in range(m)]

ans = [1]*n

s = 0
m = n

for i in list:
    if i[0] > s:
        s = i[0]
    if i[1] < m:
        m = i[1]
if m>=s:
    print(m-s+1)
else:
    print(0)