import sys

from itertools import accumulate



def main():

    input = sys.stdin.readline

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

    acc = [0] * (N+1)

    for _ in range(M):

        left, right = list(map(int, input().split()))

        acc[left-1] += 1

        acc[right] -= 1



    cnt = 0

    for a in accumulate(acc):

        if a == M:

            cnt += 1



    return cnt





if __name__ == '__main__':

    print((main()))

import sys



def main():

    input = sys.stdin.readline

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

    L = 0

    R = 10**5 + 1

    for _ in range(M):

        left, right = list(map(int, input().split()))

        L = max(L, left)

        R = min(R, right)



    return max(R - L + 1, 0)





if __name__ == '__main__':

    print((main()))

import sys
from itertools import accumulate


def main():
    input = sys.stdin.readline
    N, M = list(map(int, input().split()))
    acc = [0] * (N + 1)
    for _ in range(M):
        left, right = list(map(int, input().split()))
        acc[left - 1] += 1
        acc[right] -= 1
    cnt = 0
    for a in accumulate(acc):
        if a == M:
            cnt += 1
    return cnt


if __name__ == "__main__":
    print((main()))

import sys


def main():
    input = sys.stdin.readline
    N, M = list(map(int, input().split()))
    L = 0
    R = 10**5 + 1
    for _ in range(M):
        left, right = list(map(int, input().split()))
        L = max(L, left)
        R = min(R, right)
    return max(R - L + 1, 0)


if __name__ == "__main__":
    print((main()))

-from itertools import accumulate -    acc = [0] * (N + 1) +    L = 0 +    R = 10**5 + 1 -        acc[left - 1] += 1 -        acc[right] -= 1 -    cnt = 0 -    for a in accumulate(acc): -        if a == M: -            cnt += 1 -    return cnt +        L = max(L, left) +        R = min(R, right) +    return max(R - L + 1, 0)