#include #include #include #include #include using namespace std; int main() { int n, r; while(cin >> n >> r){ if(n==0 && r == 0){ break; } list ls; for(int i=0; i next; cin >> pp >> c; list::iterator p = ls.begin(); for(int j=1; j::iterator q = p; for(int j=0; j::iterator r = p; next.insert(next.end(), q, r); next.insert(next.end(), ls.begin(), q); next.insert(next.end(), r, ls.end()); ls = next; } cout << ls.front() << endl; } return 0; }