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