Go: package main

import "fmt"

func main() {
	var n, r int
	fmt.Scan(&n, &r)
	for n != 0 || r != 0 {
		arr := make([]int, n)
		for i := range arr {
			arr[i] = len(arr) - i
		}

		for i := 0; i < r; i++ {
			var p, c int
			fmt.Scan(&p, &c)
			mid, top, last := arr[:p-1], arr[p-1:p-1+c], arr[p-1+c:]
			arr = append(append(append([]int{}, top...), mid...), last...)
		}
		fmt.Println(arr[0])
		fmt.Scan(&n, &r)
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    for(;;){
        ll N, R;
        cin >> N >> R;

        if(N==0 && R==0){
            return 0;
        }

        vector<ll> A(N);
        FOR(i, 0, N){
            A[i] = i+1;
        }

        while(R--){
            ll p, c;
            cin >> p >> c;

            // 右手に取る
            vector<ll> temp;
            ll L = N-p+1-c;
            FOR(i, L, L+c){
                temp.push_back(A[i]);
            }

            // おろす
            FOR(i, L+c, N){
                A[i-c] = A[i];
            }

            // tempを上に乗せる
            ll insert_index = N-c;
            FOR(i, 0, c){
                A[insert_index] = temp[i];
                insert_index++;
            }
        }
        p(A[N-1]);
    }
    
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n, r, p, c;
	while (true) {
		cin >> n >> r;

		if (n == 0 && r == 0) {
			break;
		}
		vector<int> cards;
		for (int i = 1; i <= n; i++) {
			cards.push_back(i);
		}

		for (; r > 0; r--) {
			cin >> p >> c;

			p = n - p - c + 1;
			for (; c > 0; c--) {
				cards.push_back(cards[p]);
				cards.erase(cards.begin() + p);
			}
		}
		cout << cards.back() << '\n';
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

   while(1){

      int n, r;
      cin>> n>> r;
      if(n==0&&r==0) break;
      int a[n];
      for(int i=0; i<n; i++) a[i]=n-i;
      for(int i=0; i<r; i++){
         int p, c;
         cin>> p>> c;
         int b[c];
         for(int j=p-1; j<p+c-1; j++){
            b[j-(p-1)]=a[j];
         }
         for(int j=p+c-1; j>c; j--){
            a[j]=a[j-c];
         }
         for(int j=0; j<c; j++){
            a[j]=b[j];
         }
      }

      cout<< a[0]<< endl;
   }
   return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

vector<int> huda(55);

void shuffle(int p,int c) {
	vector<int> tmp(p - 1);
	for (int i = 0; i < p - 1; ++i) tmp[i] = huda[i];
	for (int i = 0; i < c; ++i) huda[i] = huda[i + p - 1];
	for (int i = 0; i < p - 1; ++i) huda[c + i] = tmp[i];
}

int main() {
	int n, r;
	while (cin >> n >> r && n != 0 && r != 0) {
		for (int i = 1; i <= n; ++i) huda[n - i] = i;
		for (int i = 0; i < r; ++i) {
			int p, c;
			cin >> p >> c;
			shuffle(p, c);
		}
		cout << huda[0] << endl;
	}


	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,r,c,p;
    vector<int> s,s2;
    while(1){
        cin >> n >> r;
        if(n==0&&r==0)  break;
        for(int i=1;i<=n;i++){
            s.push_back(i);
        }
        while(r--){
            cin >> p >> c;
            for(int i=0;i<n-c-p+1;i++){
                s2.push_back(s[i]);
            }
            for(int i=n-p+1;i<n;i++){
                s2.push_back(s[i]);
            }
            for(int i=n-c-p+1;i<n-p+1;i++){
                s2.push_back(s[i]);
            }
            s.clear();
            for(int i=0;i<n;i++){
                s.push_back(s2[i]);
               cout << s[i] << "  ";
            }
            cout << endl;
            s2.clear();
        }
        cout << s[n-1] << "\n";
        s.clear();
    }
}

C++: #include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>


#define mp(a,b) make_pair(a,b)
#define rep(i,n) for (size_t i = 0; i < (n); ++i)
typedef long long ll;


using namespace std;
int main(){
  int n,r;
  while(cin >> n >> r and (n bitor r) != 0){
    string s;
    for (int i = n; i > 0; --i)  s.push_back(i+'0');
    int p,c;
    for(int i = 0;i < r;i++){
      cin >> p >> c;
      s = s.substr(p-1,c) + s.substr(0,p-1)
	+ s.substr(p+c-1);
    }
    cout << s[0] << endl;
  }
  return 0;
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){

	while(1){
		int n,r;
		cin>> n>> r;
		if(n==0 && r==0) break;
		vector<vector<int> > a(2, vector<int> (n));
		for(int i=0;i<n;i++){
			a[0][i] = n-i;
			a[1][i] = n-i;
		}
		
		for(int i=0;i<r;i++){
			int p, c;
			cin>> p>> c;
			for(int j=0;j<c+p-1;j++){
				if(j<c){
					a[1][j] = a[0][j+p-1];
				}else{
					a[1][j] = a[0][j-c];
				}
			}
			for(int j=0;j<n;j++){
				a[0][j] = a[1][j];
			}
		}
		
		cout<< a[0][0]<< endl;
	}
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

C++: #include <iostream>

using namespace std;

int main (void) {
  int before[50], after[50];
  int n, r, p, c;
  int i, j, k;


  while(1) {
    cin >> n;
    
    for(i = 0; i < n; i++) {
      before[i] = n - i;
      //    cout << before[i] << endl;
    }
    //    cout << endl;
    
    cin >> r;
    
    if (n == 0 && r == 0) break;
    
    for(i = 0; i < r; i++) {
      cin >> p; cin >> c;
      
      for(j = 0; j < c; j++) {
	after[j] = before[p-1+j];
      }
      for(k = 0; k < p-1; j++, k++) {
	after[j] = before[k];
      }
      for(; j < n; j++) {
	after[j] = before[j];
      }
      
      for(j = 0; j < n; j++) {
	before[j] = after[j];
	//	cout << after[j] << endl;
      }

      //cout << endl;
    }

    cout << after[0] << endl;
  }
  
  return 0;
}

C++: #include <iostream>
using namespace std;

int main(){
	int n, r;
	while(cin >> n >> r){
		if(n == 0 && r == 0) break;
		const int max = 50;
		int cards[max + 1];
		int pcards[max + 1];
		int ccards[max + 1];
		for(int i = 1; i <= n; i++)
			cards[i] = n - i + 1;
		for(int j = 0; j < r; j++){
			int p, c;
			int k = 1;
			int l = 1;
			cin >> p >> c;
			for(;k < p; k++)
				pcards[k] = cards[k];
			for(;k < p + c; k++)
				ccards[k - p + 1] = cards[k];
			for(; l <= c; l++)
				cards[l] = ccards[l];
			for(; l < p + c; l++)
				cards[l] = pcards[l - c];
		}
		cout << cards[1] << endl;
	}
	return 0;
}