N, M = list(map(int,input().rstrip().split()))
Amin = 1
Amax = N
for i in range(M):
    L, R = list(map(int,input().rstrip().split()))
    Amin = max(Amin,L)
    Amax = min(Amax,R)
    if Amin>Amax:
        print(0)
        break
else:
    print(Amax-Amin+1) N, M = list(map(int,input().rstrip().split())) N list(map(int,input().rstrip().split())) list map(int,input().rstrip().split()) map int input().rstrip().split() ().rstrip().split ().rstrip() ().rstrip () input rstrip split M Amin = 1 Amin 1 Amax = N Amax N for i in range(M):
    L, R = list(map(int,input().rstrip().split()))
    Amin = max(Amin,L)
    Amax = min(Amax,R)
    if Amin>Amax:
        print(0)
        break
else:
    print(Amax-Amin+1) i range(M) range M L, R = list(map(int,input().rstrip().split())) L list(map(int,input().rstrip().split())) list map(int,input().rstrip().split()) map int input().rstrip().split() ().rstrip().split ().rstrip() ().rstrip () input rstrip split R Amin = max(Amin,L) Amin max(Amin,L) max Amin L Amax = min(Amax,R) Amax min(Amax,R) min Amax R if Amin>Amax:
        print(0)
        break Amin>Amax Amin Amax print(0) print 0 break print(Amax-Amin+1) print Amax-Amin+1 Amax-Amin Amax Amin 1 Amin = 1 1 Amin R = list(map(int,input().rstrip().split())) list(map(int,input().rstrip().split())) R M = list(map(int,input().rstrip().split())) list(map(int,input().rstrip().split())) M Amin = max(Amin,L) max(Amin,L) Amin Amax = min(Amax,R) min(Amax,R) Amax N, M = list(map(int,input().rstrip().split())) list(map(int,input().rstrip().split())) N Amax = N N Amax L, R = list(map(int,input().rstrip().split())) list(map(int,input().rstrip().split())) L
N, M = list(map(int,input().rstrip().split()))
Amin = 1
Amax = N
for i in range(M):
    L, R = list(map(int,input().rstrip().split()))
    Amin = max(Amin,L)
    Amax = min(Amax,R)
    if Amin>Amax:
        print(0)
        break
else:
    print(Amax-Amin+1)