import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N, M = rl()
LR = []
for i in range(M):
	LR.append(rl())
cnts = [0]*(N+1)
for l, r in LR:
	cnts[l-1] += 1
	cnts[r] -= 1
ans = 0
s = 0
for i in range(N):
	s += cnts[i]
	if s == M:
		ans += 1
print(ans) import sys, math sys math from collections import defaultdict, deque, Counter from bisect import bisect_left, bisect_right from itertools import combinations, permutations, product from heapq import heappush, heappop from functools import lru_cache input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline rs = lambda: input().strip() rs lambda: input().strip() input().strip() ().strip () input strip ri = lambda: int(input()) ri lambda: int(input()) int(input()) int input() input rl = lambda: list(map(int, input().split())) rl lambda: list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split mod = 1000000007 mod 1000000007 sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 N, M = rl() N rl() rl M LR = [] LR [] for i in range(M):
	LR.append(rl()) i range(M) range M LR.append(rl()) LR.append LR append rl() rl cnts = [0]*(N+1) cnts [0]*(N+1) [0] 0 N+1 N 1 for l, r in LR:
	cnts[l-1] += 1
	cnts[r] -= 1 l r LR cnts[l-1] += 1 cnts[l-1] cnts l-1 l 1 1 cnts[r] -= 1 cnts[r] cnts r 1 ans = 0 ans 0 s = 0 s 0 for i in range(N):
	s += cnts[i]
	if s == M:
		ans += 1 i range(N) range N s += cnts[i] s cnts[i] cnts i if s == M:
		ans += 1 s == M s M ans += 1 ans 1 print(ans) print ans input = sys.stdin.readline sys.stdin.readline input s += cnts[i] cnts[i] s ri = lambda: int(input()) lambda: int(input()) ri rs = lambda: input().strip() lambda: input().strip() rs rl = lambda: list(map(int, input().split())) lambda: list(map(int, input().split())) rl M = rl() rl() M s = 0 0 s mod = 1000000007 1000000007 mod ans = 0 0 ans N, M = rl() rl() N LR = [] [] LR ans += 1 1 ans cnts = [0]*(N+1) [0]*(N+1) cnts
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N, M = rl()
LR = []
for i in range(M):
	LR.append(rl())
cnts = [0]*(N+1)
for l, r in LR:
	cnts[l-1] += 1
	cnts[r] -= 1
ans = 0
s = 0
for i in range(N):
	s += cnts[i]
	if s == M:
		ans += 1
print(ans)
