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

L = [0]*M

R = [0]*M

ans = int(0)



for i in range(M):

    L[i],R[i] = list(map(int,input().split()))



a1 = max(L)

a2 = min(R)



ans = a2-a1+1



if ans<0 : ans = int(0)



print((int(ans)))

def examA():

    N, M = LI()

    l = 1; r = N

    for _ in range(M):

        L, R = LI()

        l = max(L,l)

        r = min(R,r)

    ans = max(0,r-l+1)

    print(ans)

    return



def examB():

    ans = 0

    print(ans)

    return



def examC():

    ans = 0

    print(ans)

    return



def examD():

    ans = 0

    print(ans)

    return



def examE():

    ans = 0

    print(ans)

    return



def examF():

    ans = 0

    print(ans)

    return



import sys,bisect,itertools,heapq,math,random

from copy import deepcopy

from heapq import heappop,heappush,heapify

from collections import Counter,defaultdict,deque

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

def I(): return int(readline())

def LI(): return list(map(int,readline().split()))

def LSI(): return list(map(str,sys.stdin.readline().split()))

def LS(): return sys.stdin.readline().split()

def SI(): return read().rstrip().decode('utf-8')

global mod,mod2,inf,alphabet,_ep

mod = 10**9 + 7

mod2 = 998244353

inf = 10**18

_ep = 10**(-12)

alphabet = [chr(ord('a') + i) for i in range(26)]



sys.setrecursionlimit(10**7)



if __name__ == '__main__':

    examA()



"""

142

12 9 1445 0 1

asd dfg hj o o

aidn

"""
N, M = list(map(int, input().split()))
L = [0] * M
R = [0] * M
ans = int(0)
for i in range(M):
    L[i], R[i] = list(map(int, input().split()))
a1 = max(L)
a2 = min(R)
ans = a2 - a1 + 1
if ans < 0:
    ans = int(0)
print((int(ans)))

def examA():
    N, M = LI()
    l = 1
    r = N
    for _ in range(M):
        L, R = LI()
        l = max(L, l)
        r = min(R, r)
    ans = max(0, r - l + 1)
    print(ans)
    return


def examB():
    ans = 0
    print(ans)
    return


def examC():
    ans = 0
    print(ans)
    return


def examD():
    ans = 0
    print(ans)
    return


def examE():
    ans = 0
    print(ans)
    return


def examF():
    ans = 0
    print(ans)
    return


import sys, bisect, itertools, heapq, math, random
from copy import deepcopy
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def I():
    return int(readline())


def LI():
    return list(map(int, readline().split()))


def LSI():
    return list(map(str, sys.stdin.readline().split()))


def LS():
    return sys.stdin.readline().split()


def SI():
    return read().rstrip().decode("utf-8")


global mod, mod2, inf, alphabet, _ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10 ** (-12)
alphabet = [chr(ord("a") + i) for i in range(26)]
sys.setrecursionlimit(10**7)
if __name__ == "__main__":
    examA()
"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

-N, M = list(map(int, input().split())) -L = [0] * M -R = [0] * M -ans = int(0) -for i in range(M): -    L[i], R[i] = list(map(int, input().split())) -a1 = max(L) -a2 = min(R) -ans = a2 - a1 + 1 -if ans < 0: -    ans = int(0) -print((int(ans))) +def examA(): +    N, M = LI() +    l = 1 +    r = N +    for _ in range(M): +        L, R = LI() +        l = max(L, l) +        r = min(R, r) +    ans = max(0, r - l + 1) +    print(ans) +    return + + +def examB(): +    ans = 0 +    print(ans) +    return + + +def examC(): +    ans = 0 +    print(ans) +    return + + +def examD(): +    ans = 0 +    print(ans) +    return + + +def examE(): +    ans = 0 +    print(ans) +    return + + +def examF(): +    ans = 0 +    print(ans) +    return + + +import sys, bisect, itertools, heapq, math, random +from copy import deepcopy +from heapq import heappop, heappush, heapify +from collections import Counter, defaultdict, deque + +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines + + +def I(): +    return int(readline()) + + +def LI(): +    return list(map(int, readline().split())) + + +def LSI(): +    return list(map(str, sys.stdin.readline().split())) + + +def LS(): +    return sys.stdin.readline().split() + + +def SI(): +    return read().rstrip().decode("utf-8") + + +global mod, mod2, inf, alphabet, _ep +mod = 10**9 + 7 +mod2 = 998244353 +inf = 10**18 +_ep = 10 ** (-12) +alphabet = [chr(ord("a") + i) for i in range(26)] +sys.setrecursionlimit(10**7) +if __name__ == "__main__": +    examA() +""" +142 +12 9 1445 0 1 +asd dfg hj o o +aidn +"""