input_nk = gets.chomp
n,m = input_nk.split.collect{ |item| item.to_i}
l = []
r = []
card = []
n.times do |i|
  card[i] = i+1
end
min = 0
max = 0
m.times do |i|
  input = gets.chomp
  l,r = input.split.collect{ |item| item.to_i}
  card.delete_if{ |item| item < l}
  card.delete_if{ |item| item > r}
end
puts card.size