n,m = gets.split().map(&:to_i)
l = []
r = []
y = 0
m.times do
  x = gets.split().map(&:to_i)
  l << x[0]
  r << x[1]
  if x[0] == x[1]
    y = 1
  end
end
min = l.sort.reverse.first
max = r.sort.first
ans = max - min + 1
if y == 0
  puts ans
else
  puts 1
end