#!/usr/bin/env python3

import sys

input = lambda: sys.stdin.readline()[:-1]

sys.setrecursionlimit(10**8)

inf = float('inf')

mod = 10**9+7





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

data = [list(map(int, input().split())) for i in range(m)]











l, r = 0, 10**6

for i, j in data:

	l = max(l, i)

	r = min(r, j)

print((max(0, r-l+1)))

#!/usr/bin/env python3

import sys

input = lambda: sys.stdin.buffer.readline()[:-1]

sys.setrecursionlimit(10**8)

inf = float('inf')

mod = 10**9+7





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

data = [list(map(int, input().split())) for i in range(m)]











l, r = 0, 10**6

for i, j in data:

	l = max(l, i)

	r = min(r, j)

print((max(0, r-l+1)))

#!/usr/bin/env python3
import sys

input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float("inf")
mod = 10**9 + 7
n, m = list(map(int, input().split()))
data = [list(map(int, input().split())) for i in range(m)]
l, r = 0, 10**6
for i, j in data:
    l = max(l, i)
    r = min(r, j)
print((max(0, r - l + 1)))

#!/usr/bin/env python3
import sys

input = lambda: sys.stdin.buffer.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float("inf")
mod = 10**9 + 7
n, m = list(map(int, input().split()))
data = [list(map(int, input().split())) for i in range(m)]
l, r = 0, 10**6
for i, j in data:
    l = max(l, i)
    r = min(r, j)
print((max(0, r - l + 1)))

-input = lambda: sys.stdin.readline()[:-1] +input = lambda: sys.stdin.buffer.readline()[:-1]