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;
int main() {
  int n,r,p,c;
  vector<int> ans;
  while(cin >> n,n){
    cin >> r;
    vector<int> v,q;
    for(int i = n;i > 0;i--)v.push_back(i);
    for(int i = 0;i < r;i++){
      cin >> p >> c;
      for(int j = 0;j < p - 1;j++)q.push_back(v[j]);
      for(int j = p - 1;j < p + c - 1;j++)v[j - p + 1] = v[j];
      for(int j = c;j < p + c - 1;j++)v[j] = q[j - c];
    }
    ans.push_back(v[0]);
  }
  for(int i = 0;i < ans.size() - 1;i++)cout << ans[i] << endl;
  cout << ans[ans.size() - 1];
}

C++: /*** ??±????????£????????? ***/

#include <bits/stdc++.h>
using namespace std;

int main(){
	int n, r;
	int p, c;
	int x;
	vector<int> huda;
	vector<int>::iterator itr;
	
	cin >> n;
	cin >> r;
	for(int i=0; i<n; i++) huda.push_back(i+1);
	
	while(n!=0 && r!=0){
		for(int i=0; i<r; ++i){
			cin >> p;
			cin >> c;
			
			for(int j=0; j<c; ++j){
				itr = huda.begin()+(n-p);
				huda.push_back(*itr);
				huda.erase(huda.begin()+(n-p));
			}
		}
		
		cout << *huda.end() << endl;
		
		cin >> n;
		cin >> r;
		for(vector<int>::iterator it=huda.begin(); it!=huda.end(); it++){
			cout << *it << endl;
		} 
		cout << endl;
		huda.clear();
		for(int i=0; i<n; i++) huda.push_back(i+1);
	}
	
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#define pi 3.14159
using namespace std;


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


	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    while(true){
        int n,r; 
        cin>>n>>r; 
        if(n==0&&r==0)
            break; 
        vi res(n); 
        rep(i,0,n)
            res[i]=n-i; 
        rep(i,0,r){
            int p,c; 
            cin>>p>>c; 
            vi st(p-1); 
            //上からp-1枚保管
            rep(j,0,p-1){
                st[j]=res[j]; 
            }
            //c枚を上に
            rep(j,0,c){
                res[j]=res[p-1+j];
            }
            //p-1枚を下に
            rep(j,0,p-1){
                res[j+c]=st[j]; 
            }
        }
        cout<<res[0]<<endl; 
    }
       
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)

int main(){
    int n, r;
    while(cin >>n >>r && n){
        vector<int> v;
        for(int i = n; i >= 1; --i) v.push_back(i);

        REP(i, r){
            int p, c;
            cin >>p >>c;
            vector<int> nv;
            FOR(j, p - 1, p + c - 1) nv.push_back(v[j]);
            FOR(j, 0, p - 1) nv.push_back(v[j]);
            FOR(j, p + c - 1, n) nv.push_back(v[j]);
            v = nv;
        }
        cout <<v[0] <<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<iomanip>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{"; for(auto nth : list){ cout << nth << " ";}cout << "}" << endl;

using namespace std;

int main(){

	while(true){
		int a,b;
		cin >> a >> b;
				
		if(a==0&&b==0) break;

		int card[a];
		
			for(int i=a;0<i;i--){
				card[a-i]=i;
			}
			for(int i=0;i<b;i++){
				int c,d;
				cin >> c >> d;
				rotate(card,card+c-1,card+c+d-1);
			}
			cout << card[0] << endl;

	}
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

typedef pair<int, int> P;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
  int N, r;
  while( cin >> N >> r, N | r ){
    vector<P> ope( r );
    REP( i, r ){
      int p, c; cin >> p >> c;
      ope.emplace_back( p, c );
    }

    int t = 1;
    REPR( i, ope.size() - 1 ){
      if( t <= ope[i].second ){
        t += ope[i].first - 1;
      }else{
        if( t <= ope[i].first + ope[i].second - 1 ){
          t -= ope[i].second;
        }
      }
    }
    cout << N - t + 1 << endl;
  }
}

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

int main() {
int N,R,p,c;
while (cin>>N>>R&&N) { 
	int A[100]={};
	for(int i=0;i<N;i++){
		A[i]=i+1;
	}
	reverse(A,A+N);
	for (int i=0; i<R; ++i) {
	cin >> p >> c ;
	rotate(A,A+p,A+p+c);

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

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

using namespace std;

int n,r;
vector<int> ans;
int main(){
	while(1){
		vector<int> m;
		cin >> n >> r;
		if(n + r == 0) break;
		for(int i = 1;i <= n;i++){
			m.push_back(i);
		}
		for(int i = 0; i < r;i++){
			int c,p;
			cin >> p >> c;
			vector<int> nm;
			
			for(int j = 0;j < n;j++){
				if(j<n-p-c+1 || n-p+1<=j){
					nm.push_back(m[j]);
				}
			}
			for(int j = n-p-c+1;j < n-p+1;j++){
				nm.push_back(m[j]);
			}
			
			m = nm;
		}
		ans.push_back(m[n-1]);
	}
	for(int i = 0;i < ans.size();i++){
		cout << ans[i] << endl;
	}
}

C++: #include<stdio.h>

int main(void)
{

  int n[10000]={};
  int r[10000]={};
  int s=0;
  int l=0;
  int x[1000]={};
  int k=0;
  int i=0;
  int j=0;
  int dmm=0;
  
  while(1){
   scanf("%d  %d/n", &n[s], &r[l]);
   
   if(n[s]==0&&r[l]==0)
     break;

   s++;
   l++;
  }
  
  
  s=0;
  l=0;
  
  while(1){
    for(i=0;i<n[s];i++)
      x[i]=n[s]-i;
    int m=l;
    int s2=s;
    for(k=0;k<r[m];k++){
      l++;
      for(i=0;i<r[l];i++){
	dmm=x[n[s+1]-1+i];
	for(j=n[s+1]+i-1;j>i;j--){
	  x[j]=x[j-1];
	}
	x[i]=dmm;
      }
      s++;
    }
    printf("%d\n",x[0]);

    s++;
    l++;

    if(n[s]==0&&r[l]==0)
      break;

  }

    
      
  return 0;
}