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

min_i = 1
max_i = n

for i in range(m):
    l,r = map(int,input().split())
    min_i = max(min_i,l)
    max_i = min(max_i,r)

if max_i-min_i>=0:
    print(max_i-min_i+1)
else:
    print(0) n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m min_i = 1 min_i 1 max_i = n max_i n for i in range(m):
    l,r = map(int,input().split())
    min_i = max(min_i,l)
    max_i = min(max_i,r) i range(m) range m l,r = map(int,input().split()) l map(int,input().split()) map int input().split() ().split () input split r min_i = max(min_i,l) min_i max(min_i,l) max min_i l max_i = min(max_i,r) max_i min(max_i,r) min max_i r if max_i-min_i>=0:
    print(max_i-min_i+1)
else:
    print(0) max_i-min_i>=0 max_i-min_i max_i min_i 0 print(max_i-min_i+1) print max_i-min_i+1 max_i-min_i max_i min_i 1 print(0) print 0 l,r = map(int,input().split()) map(int,input().split()) l max_i = n n max_i n,m = map(int,input().split()) map(int,input().split()) n min_i = 1 1 min_i min_i = max(min_i,l) max(min_i,l) min_i m = map(int,input().split()) map(int,input().split()) m r = map(int,input().split()) map(int,input().split()) r max_i = min(max_i,r) min(max_i,r) max_i
n,m = map(int,input().split())

min_i = 1
max_i = n

for i in range(m):
    l,r = map(int,input().split())
    min_i = max(min_i,l)
    max_i = min(max_i,r)

if max_i-min_i>=0:
    print(max_i-min_i+1)
else:
    print(0)