N,M=map(int,input().split())
temp=0
TEMP=N-1
for i in range(M):
    a,b=map(int,input().split())
    if b-1<temp or TEMP<a-1:
        print(0)
        exit()
    if a-1>temp:
        temp=a-1
    if TEMP>b-1:
        TEMP=b-1
    
print(TEMP-temp+1) N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M temp=0 temp 0 TEMP=N-1 TEMP N-1 N 1 for i in range(M):
    a,b=map(int,input().split())
    if b-1<temp or TEMP<a-1:
        print(0)
        exit()
    if a-1>temp:
        temp=a-1
    if TEMP>b-1:
        TEMP=b-1
     i range(M) range M a,b=map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b if b-1<temp or TEMP<a-1:
        print(0)
        exit()
     b-1<temp or TEMP<a-1 b-1<temp b-1 b 1 temp TEMP<a-1 TEMP a-1 a 1 print(0) print 0 exit() exit if a-1>temp:
        temp=a-1
     a-1>temp a-1 a 1 temp temp=a-1 temp a-1 a 1 if TEMP>b-1:
        TEMP=b-1
     TEMP>b-1 TEMP b-1 b 1 TEMP=b-1 TEMP b-1 b 1 print(TEMP-temp+1) print TEMP-temp+1 TEMP-temp TEMP temp 1 N,M=map(int,input().split()) map(int,input().split()) N M=map(int,input().split()) map(int,input().split()) M temp=0 0 temp TEMP=N-1 N-1 TEMP b=map(int,input().split()) map(int,input().split()) b TEMP=b-1 b-1 TEMP a,b=map(int,input().split()) map(int,input().split()) a temp=a-1 a-1 temp
N,M=map(int,input().split())
temp=0
TEMP=N-1
for i in range(M):
    a,b=map(int,input().split())
    if b-1<temp or TEMP<a-1:
        print(0)
        exit()
    if a-1>temp:
        temp=a-1
    if TEMP>b-1:
        TEMP=b-1
    
print(TEMP-temp+1)
