deck = []
for i in 1..50 do
    deck << i
end
while true
    a = gets.split().map {|x| x.to_i}
    if a[0]==0 and a[1]==0 then
        break
    end
    tmp = deck.slice!(-a[0]..-(a[0]-a[1]+1)) 
    deck = deck + tmp
end
puts deck[49]