def INT():
    return int(input())

def LI():
    return list(map(int, input().split()))

def MI():
    return map(int, input().split())

N, M = MI()
gate = [0] * (N + 2)
ans = 0

for _ in range(M):
    L, R = MI()
    gate[L] += 1
    gate[R + 1] -= 1

for i in range(1, N + 1):
    gate[i] += gate[i - 1]
    
for i in range(1, N + 1):
    if gate[i] == M:
        ans += 1
        
print(ans) def INT():
    return int(input()) INT return int(input()) int(input()) int input() input def LI():
    return list(map(int, input().split())) LI return list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def MI():
    return map(int, input().split()) MI return map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split N, M = MI() N MI() MI M gate = [0] * (N + 2) gate [0] * (N + 2) [0] 0 N + 2 N 2 ans = 0 ans 0 for _ in range(M):
    L, R = MI()
    gate[L] += 1
    gate[R + 1] -= 1 _ range(M) range M L, R = MI() L MI() MI R gate[L] += 1 gate[L] gate L 1 gate[R + 1] -= 1 gate[R + 1] gate R + 1 R 1 1 for i in range(1, N + 1):
    gate[i] += gate[i - 1]
     i range(1, N + 1) range 1 N + 1 N 1 gate[i] += gate[i - 1] gate[i] gate i gate[i - 1] gate i - 1 i 1 for i in range(1, N + 1):
    if gate[i] == M:
        ans += 1
         i range(1, N + 1) range 1 N + 1 N 1 if gate[i] == M:
        ans += 1
         gate[i] == M gate[i] gate i M ans += 1 ans 1 print(ans) print ans N, M = MI() MI() N M = MI() MI() M def MI():
    return map(int, input().split()) def MI():
    return map(int, input().split()) MI gate = [0] * (N + 2) [0] * (N + 2) gate ans += 1 1 ans def INT():
    return int(input()) def INT():
    return int(input()) INT def LI():
    return list(map(int, input().split())) def LI():
    return list(map(int, input().split())) LI L, R = MI() MI() L R = MI() MI() R ans = 0 0 ans
def INT():
    return int(input())

def LI():
    return list(map(int, input().split()))

def MI():
    return map(int, input().split())

N, M = MI()
gate = [0] * (N + 2)
ans = 0

for _ in range(M):
    L, R = MI()
    gate[L] += 1
    gate[R + 1] -= 1

for i in range(1, N + 1):
    gate[i] += gate[i - 1]
    
for i in range(1, N + 1):
    if gate[i] == M:
        ans += 1
        
print(ans)