n,m = map(int,input().split())
min_card,max_card = 0,n
for i in range(m):
    l,r = map(int,input().split())
    min_card = max(min_card,l)
    max_card = min(max_card,r)
#print(min_card,max_card)
if min_card<=max_card:
    print(max_card-min_card+1)
else:
    print(0) n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m min_card,max_card = 0,n min_card 0 max_card n for i in range(m):
    l,r = map(int,input().split())
    min_card = max(min_card,l)
    max_card = min(max_card,r)
#print(min_card,max_card) 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_card = max(min_card,l) min_card max(min_card,l) max min_card l max_card = min(max_card,r) max_card min(max_card,r) min max_card r if min_card<=max_card:
    print(max_card-min_card+1)
else:
    print(0) min_card<=max_card min_card max_card print(max_card-min_card+1) print max_card-min_card+1 max_card-min_card max_card min_card 1 print(0) print 0 l,r = map(int,input().split()) map(int,input().split()) l n,m = map(int,input().split()) map(int,input().split()) n min_card,max_card = 0,n 0 min_card r = map(int,input().split()) map(int,input().split()) r max_card = 0,n n max_card min_card = max(min_card,l) max(min_card,l) min_card m = map(int,input().split()) map(int,input().split()) m max_card = min(max_card,r) min(max_card,r) max_card
n,m = map(int,input().split())
min_card,max_card = 0,n
for i in range(m):
    l,r = map(int,input().split())
    min_card = max(min_card,l)
    max_card = min(max_card,r)
#print(min_card,max_card)
if min_card<=max_card:
    print(max_card-min_card+1)
else:
    print(0)