def shuffle(array, p, c)
  temp = Array.new
  c.times do |i|
    temp[i] = array[i + p - 1]
  end
  j = c - 1
  while j >= 0 do
    array.delete_at(j + p - 1)
    j -= 1
  end
  array.insert(0, temp)
  array.flatten!
end
cards, operations = 1
until cards == 0 && operations == 0 do
deck = Array.new
cards, operations = gets.split(" ").map{|i| i.to_i}
deck = (1..cards).to_a.reverse
ops = Array.new
j = 0
operations.times do
  ops[j], ops[j+1] = gets.split(" ").map{|i| i.to_i}
  shuffle(deck, ops[j], ops[j+1])
  j+=2
end
puts deck.first
end