#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 12, 2020 15:41:56 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from sys import stdin
input = stdin.readline


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

  min_ = -float('inf')
  max_ = float('inf')
  for _ in range(M):
    L, R = map(int, input().split())
    min_ = max(min_, L)
    max_ = min(max_, R)

  ans = 0
  for i in range(1, N+1):
    (max_ - min_ + 1)
    if min_<=i<=max_:
      ans += 1
  print(ans)


if(__name__ == '__main__'):
  main() __giturl__ = "$URL$" __giturl__ "$URL$" from sys import stdin input = stdin.readline input stdin.readline stdin readline def main():
  N, M = list(map(int, input().split()))

  min_ = -float('inf')
  max_ = float('inf')
  for _ in range(M):
    L, R = map(int, input().split())
    min_ = max(min_, L)
    max_ = min(max_, R)

  ans = 0
  for i in range(1, N+1):
    (max_ - min_ + 1)
    if min_<=i<=max_:
      ans += 1
  print(ans) main N, M = list(map(int, input().split())) N list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split M min_ = -float('inf') min_ -float('inf') float('inf') float 'inf' max_ = float('inf') max_ float('inf') float 'inf' for _ in range(M):
    L, R = map(int, input().split())
    min_ = max(min_, L)
    max_ = min(max_, R)

   _ range(M) range M L, R = map(int, input().split()) L map(int, input().split()) map int input().split() ().split () input split R min_ = max(min_, L) min_ max(min_, L) max min_ L max_ = min(max_, R) max_ min(max_, R) min max_ R ans = 0 ans 0 for i in range(1, N+1):
    (max_ - min_ + 1)
    if min_<=i<=max_:
      ans += 1
   i range(1, N+1) range 1 N+1 N 1 max_ - min_ + 1 max_ - min_ max_ min_ 1 if min_<=i<=max_:
      ans += 1
   min_<=i<=max_ min_<=i min_ i max_ ans += 1 ans 1 print(ans) print ans if(__name__ == '__main__'):
  main() __name__ == '__main__' __name__ '__main__' main() main input = stdin.readline stdin.readline input def main():
  N, M = list(map(int, input().split()))

  min_ = -float('inf')
  max_ = float('inf')
  for _ in range(M):
    L, R = map(int, input().split())
    min_ = max(min_, L)
    max_ = min(max_, R)

  ans = 0
  for i in range(1, N+1):
    (max_ - min_ + 1)
    if min_<=i<=max_:
      ans += 1
  print(ans) def main():
  N, M = list(map(int, input().split()))

  min_ = -float('inf')
  max_ = float('inf')
  for _ in range(M):
    L, R = map(int, input().split())
    min_ = max(min_, L)
    max_ = min(max_, R)

  ans = 0
  for i in range(1, N+1):
    (max_ - min_ + 1)
    if min_<=i<=max_:
      ans += 1
  print(ans) main
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 12, 2020 15:41:56 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from sys import stdin
input = stdin.readline


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

  min_ = -float('inf')
  max_ = float('inf')
  for _ in range(M):
    L, R = map(int, input().split())
    min_ = max(min_, L)
    max_ = min(max_, R)

  ans = 0
  for i in range(1, N+1):
    (max_ - min_ + 1)
    if min_<=i<=max_:
      ans += 1
  print(ans)


if(__name__ == '__main__'):
  main()
