n = gets.to_i
m = gets.to_i
p, q, r = gets.split.map(&:to_i)
pos = Array.new(n){ |i| i+1 }
npos = Array.new(n)
m.times do 
  x, y = gets.split.map(&:to_i)
  npos[0...n-y] = pos[y..-1]
  npos[n-y...n-x] = pos[x...y]
  npos[n-x..-1] = pos[0...x]
  pos = npos
end
p pos[p-1..q-1].count{ |i| i <= r }