N,M= map(int, input().split())
L,R= map(int, input().split())
flag = True
for i in range(M-1):
    a,b= map(int, input().split())
    if a >= L and b <= R:
        L = a
        R = b
    elif L <= b and R >= b:
        R = b
    elif L <= a and R >= a:
        L = a
    elif a < L and R < b:
        L = L
    else:
        flag = False
        break
if flag:
 print(R-L+1)
else:
    print(0) N,M= map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L,R= map(int, input().split()) L map(int, input().split()) map int input().split() ().split () input split R flag = True flag True for i in range(M-1):
    a,b= map(int, input().split())
    if a >= L and b <= R:
        L = a
        R = b
    elif L <= b and R >= b:
        R = b
    elif L <= a and R >= a:
        L = a
    elif a < L and R < b:
        L = L
    else:
        flag = False
        break i range(M-1) range M-1 M 1 a,b= map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b if a >= L and b <= R:
        L = a
        R = b
    elif L <= b and R >= b:
        R = b
    elif L <= a and R >= a:
        L = a
    elif a < L and R < b:
        L = L
    else:
        flag = False
        break a >= L and b <= R a >= L a L b <= R b R L = a L a R = b R b elif L <= b and R >= b:
        R = b
     L <= b and R >= b L <= b L b R >= b R b R = b R b elif L <= a and R >= a:
        L = a
     L <= a and R >= a L <= a L a R >= a R a L = a L a elif a < L and R < b:
        L = L
     a < L and R < b a < L a L R < b R b L = L L L flag = False flag False break if flag:
 print(R-L+1)
else:
    print(0) flag print(R-L+1) print R-L+1 R-L R L 1 print(0) print 0 R = b b R a,b= map(int, input().split()) map(int, input().split()) a flag = False False flag M= map(int, input().split()) map(int, input().split()) M R = b b R R= map(int, input().split()) map(int, input().split()) R flag = True True flag N,M= map(int, input().split()) map(int, input().split()) N L,R= map(int, input().split()) map(int, input().split()) L b= map(int, input().split()) map(int, input().split()) b L = L L L L = a a L L = a a L
N,M= map(int, input().split())
L,R= map(int, input().split())
flag = True
for i in range(M-1):
    a,b= map(int, input().split())
    if a >= L and b <= R:
        L = a
        R = b
    elif L <= b and R >= b:
        R = b
    elif L <= a and R >= a:
        L = a
    elif a < L and R < b:
        L = L
    else:
        flag = False
        break
if flag:
 print(R-L+1)
else:
    print(0)