# -*- coding: utf-8 -*-



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

L, R = [None] * M, [None] * M

for i in range(M):

    L[i], R[i] = list(map(int, input().split()))



l = max(L)

r = min(R)



ans = max(r - l + 1, 0)



print(ans)

# -*- coding: utf-8 -*-



import sys

input = sys.stdin.readline



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

L, R = [None] * M, [None] * M

for i in range(M):

    L[i], R[i] = list(map(int, input().split()))



ans = max(min(R) - max(L) + 1, 0)



print(ans)

# -*- coding: utf-8 -*-
N, M = list(map(int, input().split()))
L, R = [None] * M, [None] * M
for i in range(M):
    L[i], R[i] = list(map(int, input().split()))
l = max(L)
r = min(R)
ans = max(r - l + 1, 0)
print(ans)

# -*- coding: utf-8 -*-
import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
L, R = [None] * M, [None] * M
for i in range(M):
    L[i], R[i] = list(map(int, input().split()))
ans = max(min(R) - max(L) + 1, 0)
print(ans)

+import sys + +input = sys.stdin.readline -l = max(L) -r = min(R) -ans = max(r - l + 1, 0) +ans = max(min(R) - max(L) + 1, 0)