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

max = 0
min = n+1
for i in range(m):
    if lr[i][0] > max :
        max = lr[i][0]
    if lr[i][1] < min :
        min = lr[i][1]

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

max = 0
min = n+1
for i in range(m):
    if lr[i][0] > max :
        max = lr[i][0]
    if lr[i][1] < min :
        min = lr[i][1]

if min-max >= 0:
    print(min-max+1)
else :
    print(0)
