def take(cards, x)
  head, tail = [], []

  num = 0

  cards.each do |c|
    if num + c[1] <= x
      head << c
    elsif x <= num
      tail << c
    elsif x < num + c[1]
      head << [c[0], x - num]
      tail << [c[0] + x - num, c[1] - (x - num)]
    else
      raise Error
    end

    num += c[1]
  end

  [head, tail]
end


def count(cards, r)
  res = 0

  cards.each do |c|
    res += [r - c[0] + 1, c[1]].min if c[0] <= r
  end

  res
end


n = gets.chomp.to_i
m = gets.chomp.to_i
p, q, r = gets.split.map(&:to_i)

cards = [[1, n]]

m.times do
  x, y = gets.split.map(&:to_i)

  a, cards = take(cards, x)
  b, c = take(cards, y - x)

  cards = c + b + a
end


puts count(take(take(cards, p-1)[1], q - p + 1)[0], r)