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

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

max_l = -1*float('INF')
min_r = float('INF')
for i in range(m):
    max_l = max(max_l,l[i][0])
    min_r = min(min_r,l[i][1])

ans = min_r - max_l + 1

if(ans < 0):
    print(0)
    exit()

if(ans <= n):
    print(ans)
else:
    print(n) 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 l = [list(map(int,input().split())) for i in range(m)] l [list(map(int,input().split())) for i in range(m)] max_l = -1*float('INF') max_l -1*float('INF') -1 float('INF') float 'INF' min_r = float('INF') min_r float('INF') float 'INF' for i in range(m):
    max_l = max(max_l,l[i][0])
    min_r = min(min_r,l[i][1]) i range(m) range m max_l = max(max_l,l[i][0]) max_l max(max_l,l[i][0]) max max_l l[i][0] [i] l i 0 min_r = min(min_r,l[i][1]) min_r min(min_r,l[i][1]) min min_r l[i][1] [i] l i 1 ans = min_r - max_l + 1 ans min_r - max_l + 1 min_r - max_l min_r max_l 1 if(ans < 0):
    print(0)
    exit() ans < 0 ans 0 print(0) print 0 exit() exit if(ans <= n):
    print(ans)
else:
    print(n) ans <= n ans n print(ans) print ans print(n) print n l = [list(map(int,input().split())) for i in range(m)] [list(map(int,input().split())) for i in range(m)] l max_l = -1*float('INF') -1*float('INF') max_l max_l = max(max_l,l[i][0]) max(max_l,l[i][0]) max_l m = map(int,input().split()) map(int,input().split()) m min_r = min(min_r,l[i][1]) min(min_r,l[i][1]) min_r ans = min_r - max_l + 1 min_r - max_l + 1 ans n,m = map(int,input().split()) map(int,input().split()) n min_r = float('INF') float('INF') min_r
n,m = map(int,input().split())

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

max_l = -1*float('INF')
min_r = float('INF')
for i in range(m):
    max_l = max(max_l,l[i][0])
    min_r = min(min_r,l[i][1])

ans = min_r - max_l + 1

if(ans < 0):
    print(0)
    exit()

if(ans <= n):
    print(ans)
else:
    print(n)
