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

L, R = (

    list(zip(*(list(map(int, input().split())) for _ in range(M)))) if M else

    ((), ())

)



x = 1

y = N

for l, r in zip(L, R):

    x = max(l, x)

    y = min(r, y)

ans = max(y - x + 1, 0)

print(ans)

# 入力

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

L, R = (

    list(zip(*(list(map(int, input().split())) for _ in range(M)))) if M else

    ((), ())

)



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



# 出力

print(ans)

N, M = list(map(int, input().split()))
L, R = (
    list(zip(*(list(map(int, input().split())) for _ in range(M)))) if M else ((), ())
)
x = 1
y = N
for l, r in zip(L, R):
    x = max(l, x)
    y = min(r, y)
ans = max(y - x + 1, 0)
print(ans)

# 入力
N, M = list(map(int, input().split()))
L, R = (
    list(zip(*(list(map(int, input().split())) for _ in range(M)))) if M else ((), ())
)
ans = max(min(R) - max(L) + 1, 0)
# 出力
print(ans)

+# 入力 -x = 1 -y = N -for l, r in zip(L, R): -    x = max(l, x) -    y = min(r, y) -ans = max(y - x + 1, 0) +ans = max(min(R) - max(L) + 1, 0) +# 出力