n,m =map(int,input().split())
a =[]*m
b =[]*m
for i in range(m):
        l,r =map(int,input().split())
        a.append(l)
        b.append(r)

if max(a) <=min(b):
        print(min(b)-max(a)+1)
else:
        print(0) n,m =map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m a =[]*m a []*m [] m b =[]*m b []*m [] m for i in range(m):
        l,r =map(int,input().split())
        a.append(l)
        b.append(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 a.append(l) a.append a append l b.append(r) b.append b append r if max(a) <=min(b):
        print(min(b)-max(a)+1)
else:
        print(0) max(a) <=min(b) max(a) max a min(b) min b print(min(b)-max(a)+1) print min(b)-max(a)+1 min(b)-max(a) min(b) min b max(a) max a 1 print(0) print 0 n,m =map(int,input().split()) map(int,input().split()) n a =[]*m []*m a b =[]*m []*m b r =map(int,input().split()) map(int,input().split()) r l,r =map(int,input().split()) map(int,input().split()) l m =map(int,input().split()) map(int,input().split()) m
n,m =map(int,input().split())
a =[]*m
b =[]*m
for i in range(m):
        l,r =map(int,input().split())
        a.append(l)
        b.append(r)

if max(a) <=min(b):
        print(min(b)-max(a)+1)
else:
        print(0)
