n,m = gets.split.map(&:to_i)

a = []
m.times do |i|
  a[i] = gets.split.map(&:to_i)
end


t = []
m.times do |i|
  t[i] = []
  for e in a[i][0]..a[i][1] do
    t[i].push(e)
  end
end

ans = []

if m > 1
  (m-1).times do |i|
    if i == 0
      ans = t[i-1]&t[i]
    else
      ans = ans&t[i-1]&t[i]
    end
  end

  ans = ans.select do |x|
    x <=  n
  end
  puts ans.count
else
  puts t[0].count
end


