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

l = -1

r = N+1



for _ in range(M):

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

  l = max(l,L)

  r = min(r,R)



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

print(answer)
import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



import numpy as np



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

LR = np.array(read().split(),np.int32)



L = LR[::2]; R = LR[1::2]



x = R.min() - L.max() + 1

if x < 0: x = 0

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

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N, M = list(map(int, readline().split()))
LR = np.array(read().split(), np.int32)
L = LR[::2]
R = LR[1::2]
x = R.min() - L.max() + 1
if x < 0:
    x = 0
print(x)

-N, M = list(map(int, input().split())) -l = -1 -r = N + 1 -for _ in range(M): -    L, R = list(map(int, input().split())) -    l = max(l, L) -    r = min(r, R) -answer = max(0, r - l + 1) -print(answer) +import sys + +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +import numpy as np + +N, M = list(map(int, readline().split())) +LR = np.array(read().split(), np.int32) +L = LR[::2] +R = LR[1::2] +x = R.min() - L.max() + 1 +if x < 0: +    x = 0 +print(x)