n, m = list(map(int, input().split()))

S = [None]*m

L = 0

R = n



for i in range(m):

    l, r = list(map(int, input().split()))

    L = max(l, L)

    R = min(r, R)



ans = R-L+1

if ans < 0:

    ans = 0

print(ans)
import sys

input = sys.stdin.readline



n, m = list(map(int, input().split()))

L, R = 0, n



for i in range(m):

    l, r = list(map(int, input().split()))

    L = max(l, L)

    R = min(r, R)



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

print(ans)
n, m = list(map(int, input().split()))
S = [None] * m
L = 0
R = n
for i in range(m):
    l, r = list(map(int, input().split()))
    L = max(l, L)
    R = min(r, R)
ans = R - L + 1
if ans < 0:
    ans = 0
print(ans)

import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
L, R = 0, n
for i in range(m):
    l, r = list(map(int, input().split()))
    L = max(l, L)
    R = min(r, R)
ans = max(R - L + 1, 0)
print(ans)

+import sys + +input = sys.stdin.readline -S = [None] * m -L = 0 -R = n +L, R = 0, n -ans = R - L + 1 -if ans < 0: -    ans = 0 +ans = max(R - L + 1, 0)