N, M = map(int,input().split())

L, R = 1, N

for _ in range(M):
    l, r = map(int,input().split())

    if(r < L or R < l):
        print(0)
        exit()
    else:
        L = max(l,L)
        R = min(r,R)

print(R-L+1) N, M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L, R = 1, N L 1 R N for _ in range(M):
    l, r = map(int,input().split())

    if(r < L or R < l):
        print(0)
        exit()
    else:
        L = max(l,L)
        R = min(r,R) _ range(M) range M l, r = map(int,input().split()) l map(int,input().split()) map int input().split() ().split () input split r if(r < L or R < l):
        print(0)
        exit()
    else:
        L = max(l,L)
        R = min(r,R) r < L or R < l r < L r L R < l R l print(0) print 0 exit() exit L = max(l,L) L max(l,L) max l L R = min(r,R) R min(r,R) min r R print(R-L+1) print R-L+1 R-L R L 1 l, r = map(int,input().split()) map(int,input().split()) l R = 1, N N R L = max(l,L) max(l,L) L r = map(int,input().split()) map(int,input().split()) r N, M = map(int,input().split()) map(int,input().split()) N L, R = 1, N 1 L M = map(int,input().split()) map(int,input().split()) M R = min(r,R) min(r,R) R
N, M = map(int,input().split())

L, R = 1, N

for _ in range(M):
    l, r = map(int,input().split())

    if(r < L or R < l):
        print(0)
        exit()
    else:
        L = max(l,L)
        R = min(r,R)

print(R-L+1)
