import sys, math, collections, heapq, itertools

F = sys.stdin

def single_input(): return F.readline().strip("\n")

def line_input(): return F.readline().strip("\n").split()

def gcd(a, b):

    a, b = max(a, b), min(a, b)

    while a % b > 0: a, b = b, a % b

    return b

  

def solve():

    N, M = list(map(int, line_input()))

    gate = [0 for n in range(N+1)]

    for i in range(M):

        l, r = list(map(int, line_input()))

        gate[l-1] += 1

        gate[r] -= 1

    ans = (1 if gate[0] == M else 0)

    for i in range(1, N):

        gate[i] = gate[i] + gate[i-1]

        if gate[i] == M: ans += 1

    print(ans)

    return 0

  

if __name__ == "__main__":

    solve()
import sys



def solve():

    input = sys.stdin.readline

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

    count = [0] * (N + 1)

    for _ in range(M):

        l, r = list(map(int, input().split()))

        count[l - 1] += 1

        count[r] -= 1

    ans = (1 if count[0] == M else 0)

    for i in range(1, N):

        count[i] += count[i - 1]

        if count[i] == M: ans += 1

    print(ans)



    return 0



if __name__ =="__main__":

    solve()
import sys, math, collections, heapq, itertools

F = sys.stdin


def single_input():
    return F.readline().strip("\n")


def line_input():
    return F.readline().strip("\n").split()


def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a % b
    return b


def solve():
    N, M = list(map(int, line_input()))
    gate = [0 for n in range(N + 1)]
    for i in range(M):
        l, r = list(map(int, line_input()))
        gate[l - 1] += 1
        gate[r] -= 1
    ans = 1 if gate[0] == M else 0
    for i in range(1, N):
        gate[i] = gate[i] + gate[i - 1]
        if gate[i] == M:
            ans += 1
    print(ans)
    return 0


if __name__ == "__main__":
    solve()

import sys


def solve():
    input = sys.stdin.readline
    N, M = list(map(int, input().split()))
    count = [0] * (N + 1)
    for _ in range(M):
        l, r = list(map(int, input().split()))
        count[l - 1] += 1
        count[r] -= 1
    ans = 1 if count[0] == M else 0
    for i in range(1, N):
        count[i] += count[i - 1]
        if count[i] == M:
            ans += 1
    print(ans)
    return 0


if __name__ == "__main__":
    solve()

-import sys, math, collections, heapq, itertools - -F = sys.stdin - - -def single_input(): -    return F.readline().strip("\n") - - -def line_input(): -    return F.readline().strip("\n").split() - - -def gcd(a, b): -    a, b = max(a, b), min(a, b) -    while a % b > 0: -        a, b = b, a % b -    return b +import sys -    N, M = list(map(int, line_input())) -    gate = [0 for n in range(N + 1)] -    for i in range(M): -        l, r = list(map(int, line_input())) -        gate[l - 1] += 1 -        gate[r] -= 1 -    ans = 1 if gate[0] == M else 0 +    input = sys.stdin.readline +    N, M = list(map(int, input().split())) +    count = [0] * (N + 1) +    for _ in range(M): +        l, r = list(map(int, input().split())) +        count[l - 1] += 1 +        count[r] -= 1 +    ans = 1 if count[0] == M else 0 -        gate[i] = gate[i] + gate[i - 1] -        if gate[i] == M: +        count[i] += count[i - 1] +        if count[i] == M: