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

Lmax = 1

Rmin = N



for i in range(M):

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

  Lmax = max(Lmax, L)

  Rmin = min(Rmin, R)

  if Rmin < Lmax:

    print((0))

    exit()

print((Rmin-Lmax+1))
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)

  if L > R:

    print((0))

    exit()

print((R-L+1))
N, M = list(map(int, input().split()))
Lmax = 1
Rmin = N
for i in range(M):
    L, R = list(map(int, input().split()))
    Lmax = max(Lmax, L)
    Rmin = min(Rmin, R)
    if Rmin < Lmax:
        print((0))
        exit()
print((Rmin - Lmax + 1))

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)
    if L > R:
        print((0))
        exit()
print((R - L + 1))

+import sys + +input = sys.stdin.readline -Lmax = 1 -Rmin = N +L, R = 0, N -    L, R = list(map(int, input().split())) -    Lmax = max(Lmax, L) -    Rmin = min(Rmin, R) -    if Rmin < Lmax: +    l, r = list(map(int, input().split())) +    L = max(L, l) +    R = min(R, r) +    if L > R: -print((Rmin - Lmax + 1)) +print((R - L + 1))