## main

loop do
  n = gets.strip.to_i
  break if n == 0

  m = gets.strip.to_i
  pn, qn, rn = gets.strip.split(' ').map{|s| s.to_i}

  cards = (1..n).to_a
  #p cards

  m.times do
    xi, yi = gets.strip.split(' ').map{|s| s.to_i}

    cards = cards[yi...n] + cards[xi...yi] + cards[0...xi]
  end
  #p cards

  puts cards[(pn - 1)..(qn - 1)].select{|c| c <= rn}.length
end