import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

N, M = I()
count = 0
 
min_a = 1
max_b = N
 
for i in range(M):
    a,b = [int(i) for i in input().split()]
    if min_a < a:
        min_a = a
    if max_b > b:
        max_b = b
 
print(max(0, max_b-min_a+1)) import re re import sys sys import math math import itertools itertools import bisect bisect from copy import copy from collections import deque,Counter from decimal import Decimal import functools functools def v(): return input() v def k(): return int(input()) k def S(): return input().split() S def I(): return map(int,input().split()) I def X(): return list(input()) X def L(): return list(input().split()) L def l(): return list(map(int,input().split())) l def lcm(a,b): return a*b//math.gcd(a,b) lcm a a b b sys.setrecursionlimit(10 ** 6) sys.setrecursionlimit sys setrecursionlimit 10 ** 6 10 6 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 cnt = 0 cnt 0 ans = 0 ans 0 inf = float("inf") inf float("inf") float "inf" al = "abcdefghijklmnopqrstuvwxyz" al "abcdefghijklmnopqrstuvwxyz" AL = al.upper() AL al.upper() al.upper al upper N, M = I() N I() I M count = 0 count 0 min_a = 1 min_a 1 max_b = N max_b N for i in range(M):
    a,b = [int(i) for i in input().split()]
    if min_a < a:
        min_a = a
    if max_b > b:
        max_b = b
  i range(M) range M int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a,b = [int(i) for i in input().split()] a [int(i) for i in input().split()] b if min_a < a:
        min_a = a
     min_a < a min_a a min_a = a min_a a if max_b > b:
        max_b = b
  max_b > b max_b b max_b = b max_b b print(max(0, max_b-min_a+1)) print max(0, max_b-min_a+1) max 0 max_b-min_a+1 max_b-min_a max_b min_a 1 min_a = 1 1 min_a def v(): return input() def v(): return input() v cnt = 0 0 cnt def k(): return int(input()) def k(): return int(input()) k ans = 0 0 ans max_b = b b max_b M = I() I() M min_a = a a min_a N, M = I() I() N max_b = N N max_b def L(): return list(input().split()) def L(): return list(input().split()) L count = 0 0 count b = [int(i) for i in input().split()] [int(i) for i in input().split()] b def S(): return input().split() def S(): return input().split() S def I(): return map(int,input().split()) def I(): return map(int,input().split()) I def X(): return list(input()) def X(): return list(input()) X AL = al.upper() al.upper() AL inf = float("inf") float("inf") inf a,b = [int(i) for i in input().split()] [int(i) for i in input().split()] a al = "abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz" al def l(): return list(map(int,input().split())) def l(): return list(map(int,input().split())) l def lcm(a,b): return a*b//math.gcd(a,b) def lcm(a,b): return a*b//math.gcd(a,b) lcm mod = 10**9+7 10**9+7 mod
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

N, M = I()
count = 0
 
min_a = 1
max_b = N
 
for i in range(M):
    a,b = [int(i) for i in input().split()]
    if min_a < a:
        min_a = a
    if max_b > b:
        max_b = b
 
print(max(0, max_b-min_a+1))