'''
Created on 2020/09/08

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,M=map(int,pin().split())
  L,R=map(int,pin().split())
  for i in range(M-1):
    l,r=map(int,pin().split())
    if L<l and l<=R:
      L=l
    elif R<l:
      print(0)
      return
    if L<=r and r<R:
      R=r
    elif r<L:
      print(0)
      return
  print(R-L+1)
  return 
main() '''
Created on 2020/09/08

@author: harurun
''' def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,M=map(int,pin().split())
  L,R=map(int,pin().split())
  for i in range(M-1):
    l,r=map(int,pin().split())
    if L<l and l<=R:
      L=l
    elif R<l:
      print(0)
      return
    if L<=r and r<R:
      R=r
    elif r<L:
      print(0)
      return
  print(R-L+1)
  return  main import sys sys pin=sys.stdin.readline pin sys.stdin.readline sys.stdin sys stdin readline pout=sys.stdout.write pout sys.stdout.write sys.stdout sys stdout write perr=sys.stderr.write perr sys.stderr.write sys.stderr sys stderr write N,M=map(int,pin().split()) N map(int,pin().split()) map int pin().split() ().split () pin split M L,R=map(int,pin().split()) L map(int,pin().split()) map int pin().split() ().split () pin split R for i in range(M-1):
    l,r=map(int,pin().split())
    if L<l and l<=R:
      L=l
    elif R<l:
      print(0)
      return
    if L<=r and r<R:
      R=r
    elif r<L:
      print(0)
      return
   i range(M-1) range M-1 M 1 l,r=map(int,pin().split()) l map(int,pin().split()) map int pin().split() ().split () pin split r if L<l and l<=R:
      L=l
    elif R<l:
      print(0)
      return
     L<l and l<=R L<l L l l<=R l R L=l L l elif R<l:
      print(0)
      return
     R<l R l print(0) print 0 return if L<=r and r<R:
      R=r
    elif r<L:
      print(0)
      return
   L<=r and r<R L<=r L r r<R r R R=r R r elif r<L:
      print(0)
      return
   r<L r L print(0) print 0 return print(R-L+1) print R-L+1 R-L R L 1 return main() main def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,M=map(int,pin().split())
  L,R=map(int,pin().split())
  for i in range(M-1):
    l,r=map(int,pin().split())
    if L<l and l<=R:
      L=l
    elif R<l:
      print(0)
      return
    if L<=r and r<R:
      R=r
    elif r<L:
      print(0)
      return
  print(R-L+1)
  return  def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,M=map(int,pin().split())
  L,R=map(int,pin().split())
  for i in range(M-1):
    l,r=map(int,pin().split())
    if L<l and l<=R:
      L=l
    elif R<l:
      print(0)
      return
    if L<=r and r<R:
      R=r
    elif r<L:
      print(0)
      return
  print(R-L+1)
  return  main
'''
Created on 2020/09/08

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,M=map(int,pin().split())
  L,R=map(int,pin().split())
  for i in range(M-1):
    l,r=map(int,pin().split())
    if L<l and l<=R:
      L=l
    elif R<l:
      print(0)
      return
    if L<=r and r<R:
      R=r
    elif r<L:
      print(0)
      return
  print(R-L+1)
  return 
main()