N, M = input().split(' ')
N = int(N)
M = int(M)
min = 1
max = N
for i in range(M):
  l, m = input().split(' ')
  l = int(l)
  m = int(m)
  if min>m or max<l:
    print(0)
    break 
  if min < l:
    min = l
  if max > m:
    max = m
else:
  print(max-min+1) N, M = input().split(' ') N input().split(' ') ().split () input split ' ' M N = int(N) N int(N) int N M = int(M) M int(M) int M min = 1 min 1 max = N max N for i in range(M):
  l, m = input().split(' ')
  l = int(l)
  m = int(m)
  if min>m or max<l:
    print(0)
    break 
  if min < l:
    min = l
  if max > m:
    max = m
else:
  print(max-min+1) i range(M) range M l, m = input().split(' ') l input().split(' ') ().split () input split ' ' m l = int(l) l int(l) int l m = int(m) m int(m) int m if min>m or max<l:
    print(0)
    break 
   min>m or max<l min>m min m max<l max l print(0) print 0 break if min < l:
    min = l
   min < l min l min = l min l if max > m:
    max = m max > m max m max = m max m print(max-min+1) print max-min+1 max-min max min 1 N, M = input().split(' ') input().split(' ') N M = input().split(' ') input().split(' ') M max = N N max N = int(N) int(N) N max = m m max m = int(m) int(m) m min = l l min min = 1 1 min M = int(M) int(M) M l = int(l) int(l) l m = input().split(' ') input().split(' ') m l, m = input().split(' ') input().split(' ') l
N, M = input().split(' ')
N = int(N)
M = int(M)
min = 1
max = N
for i in range(M):
  l, m = input().split(' ')
  l = int(l)
  m = int(m)
  if min>m or max<l:
    print(0)
    break 
  if min < l:
    min = l
  if max > m:
    max = m
else:
  print(max-min+1)