import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time



sys.setrecursionlimit(10**7)

inf=10**20

mod=10**9+7



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

def I(): return int(eval(input()))

def LS(): return input().split()

def S(): return eval(input())



def main():

  n,m=LI()



  l=[]

  for _ in ' '*m:

    a,b=LI()

    l.append([a,1])

    l.append([b,-1])



  l=sorted(l,key=lambda x:x[1],reverse=True)

  l=sorted(l,key=lambda x:x[0])



  sm=st=0

  for x in l:

    sm+=x[1]

    if sm==m:

      st=x[0]

    if sm!=m and st!=0:

      return x[0]-st+1



  return 0



print((main()))

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy



sys.setrecursionlimit(10**7)

inf=10**20

mod=10**9+7

dd=[(-1,0),(0,1),(1,0),(0,-1)]

ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]



def LI(): return [int(x) for x in sys.stdin.readline().split()]

def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())

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

def S(): return eval(input())



def main():

  n,k=LI()

  

  l=[0]*(n+1)

  for _ in range(k):

    a,b=LI()

    l[a-1]+=1

    l[b]-=1



  for i in range(n-1):

    l[i+1]+=l[i]



  ans=0

  for x in l[:-1]:

    if x==k:

      ans+=1



  return ans



print((main()))

import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7


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


def I():
    return int(eval(input()))


def LS():
    return input().split()


def S():
    return eval(input())


def main():
    n, m = LI()
    l = []
    for _ in " " * m:
        a, b = LI()
        l.append([a, 1])
        l.append([b, -1])
    l = sorted(l, key=lambda x: x[1], reverse=True)
    l = sorted(l, key=lambda x: x[0])
    sm = st = 0
    for x in l:
        sm += x[1]
        if sm == m:
            st = x[0]
        if sm != m and st != 0:
            return x[0] - st + 1
    return 0


print((main()))

import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI():
    return [int(x) for x in sys.stdin.readline().split()]


def LI_():
    return [int(x) - 1 for x in sys.stdin.readline().split()]


def I():
    return int(sys.stdin.readline())


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


def S():
    return eval(input())


def main():
    n, k = LI()
    l = [0] * (n + 1)
    for _ in range(k):
        a, b = LI()
        l[a - 1] += 1
        l[b] -= 1
    for i in range(n - 1):
        l[i + 1] += l[i]
    ans = 0
    for x in l[:-1]:
        if x == k:
            ans += 1
    return ans


print((main()))

-import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time +import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy +dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] +ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] -    return list(map(int, input().split())) +    return [int(x) for x in sys.stdin.readline().split()] + + +def LI_(): +    return [int(x) - 1 for x in sys.stdin.readline().split()] -    return int(eval(input())) +    return int(sys.stdin.readline()) -    return input().split() +    return sys.stdin.readline().split() -    n, m = LI() -    l = [] -    for _ in " " * m: +    n, k = LI() +    l = [0] * (n + 1) +    for _ in range(k): -        l.append([a, 1]) -        l.append([b, -1]) -    l = sorted(l, key=lambda x: x[1], reverse=True) -    l = sorted(l, key=lambda x: x[0]) -    sm = st = 0 -    for x in l: -        sm += x[1] -        if sm == m: -            st = x[0] -        if sm != m and st != 0: -            return x[0] - st + 1 -    return 0 +        l[a - 1] += 1 +        l[b] -= 1 +    for i in range(n - 1): +        l[i + 1] += l[i] +    ans = 0 +    for x in l[:-1]: +        if x == k: +            ans += 1 +    return ans