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

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

if max(l) <= min(r):
    print(min(r)-max(l)+1)
else:
    print('0')