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

l = 0
r = N

for i in range(M):
    L, R = map(int, input().split())
    
    if L > l:
        l = L
            
    if R < r:
        r = R
                
    ans = r - l + 1
    if ans < 0:
        print(0)
        break

else:
    print(ans) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M l = 0 l 0 r = N r N for i in range(M):
    L, R = map(int, input().split())
    
    if L > l:
        l = L
            
    if R < r:
        r = R
                
    ans = r - l + 1
    if ans < 0:
        print(0)
        break

else:
    print(ans) i range(M) range M L, R = map(int, input().split()) L map(int, input().split()) map int input().split() ().split () input split R if L > l:
        l = L
            
     L > l L l l = L l L if R < r:
        r = R
                
     R < r R r r = R r R ans = r - l + 1 ans r - l + 1 r - l r l 1 if ans < 0:
        print(0)
        break ans < 0 ans 0 print(0) print 0 break print(ans) print ans r = N N r L, R = map(int, input().split()) map(int, input().split()) L N, M = map(int, input().split()) map(int, input().split()) N ans = r - l + 1 r - l + 1 ans r = R R r R = map(int, input().split()) map(int, input().split()) R M = map(int, input().split()) map(int, input().split()) M l = 0 0 l l = L L l
N, M = map(int, input().split())

l = 0
r = N

for i in range(M):
    L, R = map(int, input().split())
    
    if L > l:
        l = L
            
    if R < r:
        r = R
                
    ans = r - l + 1
    if ans < 0:
        print(0)
        break

else:
    print(ans)