def div_cards(cards, xi, yi)
  cds0 = []
  cds1 = []
  cds2 = []
  k = 0
  sum = 0

  while sum + cards[k][2] < xi
    cds0 << cards[k]
    sum += cards[k][2]
    k += 1
  end

  a0, c0, w = cards[k]
  w0 = xi - sum
  b0 = a0 - 1 + w0

  cds0 << [a0, b0, w0]
  sum += w0

  if w0 < w
    cards[k] = [b0 + 1, c0, w - w0]
  else
    k += 1
  end

  while sum + cards[k][2] < yi
    cds1 << cards[k]
    sum += cards[k][2]
    k += 1
  end

  a0, c0, w = cards[k]
  w0 = yi - sum
  b0 = a0 - 1 + w0

  cds1 << [a0, b0, w0]
  sum += w0

  if w0 < w
    cards[k] = [b0 + 1, c0, w - w0]
  else
    k += 1
  end

  cds2 = cards[k...cards.length]

  [cds0, cds1, cds2]
end

### 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, n]]
  #p cards

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

    cds0, cds1, cds2 = div_cards(cards, xi, yi)
    cards = cds2 + cds1 + cds0
    #p ['shffle', xi, yi]
    #p ['cds0', cds0]
    #p ['cds1', cds1]
    #p ['cds2', cds2]
    #p ['cards', cards]
  end
  #p cards

  cds0, cds1, cds2 = div_cards(cards, pn - 1, qn)
  #p cds1

  count = 0
  for cg in cds1
    if cg[0] <= rn
      count += (cg[1] <= rn ? cg[1] : rn) - cg[0] + 1
    end
  end

  puts count
end