N,M = [int(i) for i in input().split()]
c = [1, N]
for _ in range(M):
    a,b = [int(i) for i in input().split()]
    a,b = min(a,b), max(a,b)
    if c[0] <= a <= b <= c[1]:
        c = [a,b]
    elif a < c[0] <= b < c[1]:
        c = [c[0], b]
    elif c[0] < a <= c[1] < b:
        c = [a, c[1]]
    elif a <= b < c[0]:
        print(0)
        break
    elif c[1] < a <= b:
        print(0)
        break
else:
    print(c[1] - c[0] + 1) int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i N,M = [int(i) for i in input().split()] N [int(i) for i in input().split()] M c = [1, N] c [1, N] 1 N for _ in range(M):
    a,b = [int(i) for i in input().split()]
    a,b = min(a,b), max(a,b)
    if c[0] <= a <= b <= c[1]:
        c = [a,b]
    elif a < c[0] <= b < c[1]:
        c = [c[0], b]
    elif c[0] < a <= c[1] < b:
        c = [a, c[1]]
    elif a <= b < c[0]:
        print(0)
        break
    elif c[1] < a <= b:
        print(0)
        break
else:
    print(c[1] - c[0] + 1) _ range(M) range M int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a,b = [int(i) for i in input().split()] a [int(i) for i in input().split()] b a,b = min(a,b), max(a,b) a min(a,b) min a b b max(a,b) max a b if c[0] <= a <= b <= c[1]:
        c = [a,b]
    elif a < c[0] <= b < c[1]:
        c = [c[0], b]
    elif c[0] < a <= c[1] < b:
        c = [a, c[1]]
    elif a <= b < c[0]:
        print(0)
        break
    elif c[1] < a <= b:
        print(0)
        break c[0] <= a <= b <= c[1] c[0] <= a <= b c[0] <= a c[0] c 0 a b c[1] c 1 c = [a,b] c [a,b] a b elif a < c[0] <= b < c[1]:
        c = [c[0], b]
     a < c[0] <= b < c[1] a < c[0] <= b a < c[0] a c[0] c 0 b c[1] c 1 c = [c[0], b] c [c[0], b] c[0] c 0 b elif c[0] < a <= c[1] < b:
        c = [a, c[1]]
     c[0] < a <= c[1] < b c[0] < a <= c[1] c[0] < a c[0] c 0 a c[1] c 1 b c = [a, c[1]] c [a, c[1]] a c[1] c 1 elif a <= b < c[0]:
        print(0)
        break
     a <= b < c[0] a <= b a b c[0] c 0 print(0) print 0 break elif c[1] < a <= b:
        print(0)
        break c[1] < a <= b c[1] < a c[1] c 1 a b print(0) print 0 break print(c[1] - c[0] + 1) print c[1] - c[0] + 1 c[1] - c[0] c[1] c 1 c[0] c 0 1 b = min(a,b), max(a,b) max(a,b) b c = [a, c[1]] [a, c[1]] c a,b = min(a,b), max(a,b) min(a,b) a N,M = [int(i) for i in input().split()] [int(i) for i in input().split()] N c = [1, N] [1, N] c c = [a,b] [a,b] c c = [c[0], b] [c[0], b] c b = [int(i) for i in input().split()] [int(i) for i in input().split()] b a,b = [int(i) for i in input().split()] [int(i) for i in input().split()] a M = [int(i) for i in input().split()] [int(i) for i in input().split()] M
N,M = [int(i) for i in input().split()]
c = [1, N]
for _ in range(M):
    a,b = [int(i) for i in input().split()]
    a,b = min(a,b), max(a,b)
    if c[0] <= a <= b <= c[1]:
        c = [a,b]
    elif a < c[0] <= b < c[1]:
        c = [c[0], b]
    elif c[0] < a <= c[1] < b:
        c = [a, c[1]]
    elif a <= b < c[0]:
        print(0)
        break
    elif c[1] < a <= b:
        print(0)
        break
else:
    print(c[1] - c[0] + 1)