import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

A = [0] * (N + 1)
for i in range(M):
    l, r = map(int, input().split())
    l -= 1
    A[l] += 1
    A[r] -= 1
for i in range(1, N):
    A[i] += A[i - 1]
ans = 0
for a in A:
    if a == M:
        ans += 1
print(ans)
 import sys sys import itertools itertools import time time import math math import heapq heapq from collections import defaultdict sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 INF = 10 ** 18 INF 10 ** 18 10 18 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = [0] * (N + 1) A [0] * (N + 1) [0] 0 N + 1 N 1 for i in range(M):
    l, r = map(int, input().split())
    l -= 1
    A[l] += 1
    A[r] -= 1 i range(M) range M l, r = map(int, input().split()) l map(int, input().split()) map int input().split() ().split () input split r l -= 1 l 1 A[l] += 1 A[l] A l 1 A[r] -= 1 A[r] A r 1 for i in range(1, N):
    A[i] += A[i - 1] i range(1, N) range 1 N A[i] += A[i - 1] A[i] A i A[i - 1] A i - 1 i 1 ans = 0 ans 0 for a in A:
    if a == M:
        ans += 1 a A if a == M:
        ans += 1 a == M a M ans += 1 ans 1 print(ans) print ans read = sys.stdin.buffer.read sys.stdin.buffer.read read ans += 1 1 ans r = map(int, input().split()) map(int, input().split()) r INF = 10 ** 18 10 ** 18 INF N, M = map(int, input().split()) map(int, input().split()) N A = [0] * (N + 1) [0] * (N + 1) A M = map(int, input().split()) map(int, input().split()) M l -= 1 1 l readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline l, r = map(int, input().split()) map(int, input().split()) l ans = 0 0 ans
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

A = [0] * (N + 1)
for i in range(M):
    l, r = map(int, input().split())
    l -= 1
    A[l] += 1
    A[r] -= 1
for i in range(1, N):
    A[i] += A[i - 1]
ans = 0
for a in A:
    if a == M:
        ans += 1
print(ans)

