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<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 52;
int before[MAXN], after[MAXN];

int main()
{
    int n, r, p, c;
    while(cin >> n >> r && (n && r))
    {
        for(int i = n; i > 0;i--) before[n - i] = i;

        REP(r)
        {
            cin >> p >> c;

            rep(j, p - 1) after[c + j] = before[j];
            rep(j, c) after[j] = before[p - 1 + j];
            rep(j,MAXN) before[j] = after[j];
        }
        cout << before[0] << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main()
{
    while(true){
        int n,r;
        cin >> n >> r;
        if(n == 0 && r == 0) break;
        int tmp[n];
        for(int i = 0; i < n; i++){
            tmp[i] = n-i;
        }
        for(int j = 0; j < r; j++){
            int v[n];
            int p,c; cin >> p >> c;
            for(int i = 0; i < c;i++){
                v[i] = tmp[i+p-1];
            }
            for(int i = 0; i < p-1;i++){
                v[i+c] = tmp[i];
            }
            for(int i = p+c-1; i<n; i++){
                v[i] = tmp[i];
            }
            for(int i = 0; i < n; i++){
                tmp[i] = v[i];
            }
        }
        cout << tmp[0] << endl;
    }
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,R;
    cin >> N >> R;
    while(N){
        vector<int> V(N);
        iota(V.rbegin(), V.rend(), 1);
        //for(auto i:V)cout << i << endl;
        rep(i,0,R){
            int p,c;
            cin >> p >> c;
            p--;
            vector<int> tmp(p + c);
            rep(j,0,c){
                tmp[j] = V[j + p];
            }
            rep(j,c,p+c){
                tmp[j] = V[j-c];
            }
            rep(j,0,p+c){
                V[j] = tmp[j];
            }
        }
        cout << V[0] << endl;
        cin >> N >> R;
    }
}

C++: #define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int A[101];
int B[101];
int C[101];

int main()
{
	int n, r; 
	while(1) {
		cin >> n >> r;
		if (!n && !r) break;
		rep(i,0,n) A[i] = n-i;
		rep(i,0,r) {
			int t, c; cin >> t >> c;
			t--;
			// ??????
			rep(j,0,t) B[j] = A[j];
			rep(j,t,t+c) C[j-t] = A[j];
			// ??????
			rep(j,0,c) A[j] = C[j];
			rep(j,c,c+t) A[j] = B[j-c];
		}
		cout << A[0] << endl;
	}

 	return 0;
}

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

int n,r,p,c;

int main(){
  while(cin >> n >> r && n!=0 || r!=0){
    int A[n];
    for(int i=0;i<n;i++){
      A[i]=n-i;
    }
    //for (auto e:A) cout << e;
    //cout << "\n";
    for(int i=0;i<r;i++){
      cin >> p >> c;
      rotate(A,A+p-1,A+p-1+c);
    }
    cout << A[0] << endl;
  }
}

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

int N,R,p,c;
int main() {
  while (cin >> N >> R && N) {
  array<int,50> A = {};
  for (int i=0;i<N;i++) {
    A[i] = N-i;
  }
  /*  for (int i=0;i<N;i++) {
    cout << A[i];
  }
  cout << endl; */
  for (int i=0;i<R;i++) {
    cin >> p >> c;
    rotate(A.begin(),A.begin()+p-1,A.begin()+p-1+c);
    /*    for (int i=0;i<N;i++) {
      cout << A[i];
    }
    cout << endl; */
  }
  cout << A[0] << endl;
}
}

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

int main(){

while(cin >> N){
  if(N == 0) break;
  
  int A[N];
  for (int i = 0; i < N; ++i){
    A[i] = i+1; 
  }
  reverse(A,A+N);

  int r = 0; 
  cin >> r; 
  
  for (int i = 0; i < r; ++i){
    int p = 0;
    int c = 0;
    cin >> p; cin >> c;
    rotate(A,A+p-1,A+p-1+c);
  }

  cout << A[0] << endl;

}

return 0;

}

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

using namespace std;

int main(){
	int n, r;
	vector<int> card;
	vector<int> card2;
	while(true){
		cin >> n >> r;
		if(!n && !r) break;
		card.clear();
		// 1 .. n
		for(int i = 1; i <=n ; i++){
			card.push_back(i);
		}

		for(int i = 0; i < r; i++){
			int p, c;

			cin >> p >> c;
			if(n == c) continue;
			
			vector<int>::iterator it = card.end() - p - c + 1;
			
			// temp
			for(int j = 0; j < c; j++){
				card.push_back(*it);
				it++;
			}
			
			
			//erase
			card.erase(it  - c, it);
			
			it = card.begin();
			while(it != card.end()){
				cout << " " << *it ;
				it ++;
			}
			cout << endl;
			
		}
		cout << card[n-1] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int N, R, p, c;
int main() {
    while (cin >> N >> R && N) {
        vector <int> A(N,0);
        for (int i = 0; i < N; ++i) A[i] = N - i;
        for (int i = 0; i < R; ++i) {
            cin >> p >> c;
            rotate(A.begin(), A.begin()+p-1,A.begin()+c+p-1);
        }
        cout << A[0] << endl;
    }
    return 0;
}

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

int main(){
	int n,r;
	int c= 0;
	while((cin >> n)&&(cin >> r)&&(n!=0)&&(r!=0)){
		int a[n];
		int cnt=n;
		for(int i=0;i<n;i++){
			a[i] = cnt;
			cnt--;
			//cout << "a[" << i << "]" << a[i] << endl;
		}
		int p,c;
		//cout << endl;
		for(int i=0;i<r;i++){
			cin >> p;
			cin >> c;
			int b[p+c];
			//cout << p << endl;
			//cout << c << endl;
			//cout << endl;
			if(n!=c){
				for(int j=0;j<p;j++){
					b[j+c] = a[j];
				}
				for(int j=0;j<c;j++){
					b[j] = a[p+j-1];	
				}
				for(int j=0;j<p+c;j++){
					a[j] = b[j];	
					//cout << "a[" << j << "]" << a[j] << endl;
				//	cout << "b[" << j << "]" << b[j] << endl;
				}
			}
		}
		cout << a[0] << endl;
	}
}