# coding: UTF-8

import sys

#sys.setrecursionlimit(n)

import heapq

import re

import bisect

import random

import math

import itertools

from collections import defaultdict, deque

from copy import deepcopy

from decimal import *



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

a = [0] * (n + 2)

r = defaultdict(int)

for i in range(m):

    x,y = list(map(int,input().split()))

    a[x - 1] += 1

    a[y] += -1



for i in range(n + 1):

    a[i + 1] += a[i]

count = 0

flg = True

for i in range(n):

    if a[i] >= m:

        count += 1

print(count)
# coding: UTF-8

import sys

#sys.setrecursionlimit(n)

import heapq

import re

import bisect

import random

import math

import itertools

from collections import defaultdict, deque

from copy import deepcopy

from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))

readt= lambda: tuple(map(int, sys.stdin.readline().split()))

read = lambda: sys.stdin.readline().rstrip()

readi = lambda: int(read())

readmi = lambda: list(map(int, sys.stdin.readline().split()))

readms = lambda: list(map(str, sys.stdin.readline().split()))



n, m = readmi()

a = [0] * (n + 2)

r = defaultdict(int)

for i in range(m):

    x,y = readmi()

    a[x - 1] += 1

    a[y] += -1



for i in range(n + 1):

    a[i + 1] += a[i]

count = 0

flg = True

for i in range(n):

    if a[i] >= m:

        count += 1

print(count)
# coding: UTF-8
import sys

# sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

n, m = list(map(int, input().split()))
a = [0] * (n + 2)
r = defaultdict(int)
for i in range(m):
    x, y = list(map(int, input().split()))
    a[x - 1] += 1
    a[y] += -1
for i in range(n + 1):
    a[i + 1] += a[i]
count = 0
flg = True
for i in range(n):
    if a[i] >= m:
        count += 1
print(count)

# coding: UTF-8
import sys

# sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl = lambda: list(map(int, sys.stdin.readline().split()))
readt = lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: list(map(int, sys.stdin.readline().split()))
readms = lambda: list(map(str, sys.stdin.readline().split()))
n, m = readmi()
a = [0] * (n + 2)
r = defaultdict(int)
for i in range(m):
    x, y = readmi()
    a[x - 1] += 1
    a[y] += -1
for i in range(n + 1):
    a[i + 1] += a[i]
count = 0
flg = True
for i in range(n):
    if a[i] >= m:
        count += 1
print(count)

-n, m = list(map(int, input().split())) +readl = lambda: list(map(int, sys.stdin.readline().split())) +readt = lambda: tuple(map(int, sys.stdin.readline().split())) +read = lambda: sys.stdin.readline().rstrip() +readi = lambda: int(read()) +readmi = lambda: list(map(int, sys.stdin.readline().split())) +readms = lambda: list(map(str, sys.stdin.readline().split())) +n, m = readmi() -    x, y = list(map(int, input().split())) +    x, y = readmi()