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;

#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define ALL( a )        (a).begin(), (a).end()             

int main() {
	int n, r, p, c;

	while( 1 ) {
		cin >> n >> r; if( n == 0 && r == 0 ) break;
		vector<int> card( n );
		vector<int> tmp( n );
		// if n == 3 -> 3 2 1
		REP( i, n ) card[i] = n - i;

		REP( i, r ) {
			cin >> p >> c;
			tmp = card;
			REP( j, p + c - 1 ) {
				if( j < c ) card[j] = tmp[j + p - 1];
				else		card[j] = tmp[j - c];
			}
		}
		cout << card[0] << endl;
	}

}

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

using namespace std;

void solve()
{
	int n, r;
	while(cin >> n >> r, n || r)
	{
		vector<int> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			Vec[i] = n - i;
		}
		while(r--)
		{
			int p, c;
			cin >> p >> c;
			vector<int> VecBuf = Vec;
			int pos = 0;
			for(int i = p - 1; i < p + c - 1; ++i)
			{
				Vec[pos] = VecBuf[i];
				++pos;
			}
			for(int i = 0; i < p - 1; ++i)
			{
				Vec[pos] = VecBuf[i];
				++pos;
			}
			for(int i = p + c - 1; i < n; ++i)
			{
				Vec[pos] = VecBuf[i];
				++pos;
			}
		}
		cout << Vec[0] << endl;
	}
}

int main()
{
	solve();
	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;
	}
}

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

int main() {
	int N, R;
	vector<int> V, W;
	while (cin >> N >> R) {
		if (N == 0 && R == 0) break;
		V.clear();
		for (int i = 0; i < N; i++) {
			V.push_back(N - i);
		}
		for (int i = 0; i < R; i++) {
			int P, C;
			W.clear();
			cin >> P >> C;
			for (int j = P - 1; j < P + C - 1; j++) {
				W.push_back(V[j]);
			}
			for (int j = 0; j < P - 1; j++) {
				W.push_back(V[j]);
			}
			for (int j = P + C - 1; j < N; j++) {
				W.push_back(V[j]);
			}
			V = W;
		}
		cout << V[0] << endl;
	}
}

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

using namespace std;

int top_search(int,int,int,int *);
int main(){
	int n,r,c,p;
	int cnt=0;
	int top[50];
	while(1){
		cin>>n>>r;
		if(n==0&&r==0)
			break;
		int *hanahuda=new int[n];

		for (int i = n-1; i>=0 ; i--)
			hanahuda[i]=n-i;

		for(int i=0;i<r;i++){
			cin>>p>>c;
			top[cnt]=top_search(n,p,c,hanahuda);
		}
		delete[] hanahuda;
		cnt++;
	}
	for(int m=0;m<cnt;m++)
		cout<<top[m]<<endl;
	return 0;
}
int top_search(int n,int p,int c,int *hanahuda){
	int cnt=0;
	for(int k=p-1;k<p+c-1;k++){

		int nokori=hanahuda[k];

		for(int l=p-2;l>=0;l--)
			hanahuda[l+1]=hanahuda[l];


		hanahuda[cnt]=nokori;
		cnt++;
	}

	return *hanahuda;
}

C++: //
//  main.cpp
//  AOJ1129
//
//  Created by aki33524 on 2014/07/15.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[])
{
    int n, r;
    while(cin>>n>>r, n|r){
        vector<int> deck(n);
        for(int i=0; i<n; i++)
            deck[n-i-1] = i+1;
        
        int p, c;
        for(int i=0; i<r; i++){
            cin >> p >> c;
            vector<int> tmp = deck;
            for(int j=0; j<c; j++){
                deck[j] = tmp[j+p-1];
            }
            for(int j=0; j<p-1; j++){
                deck[j+c] = tmp[j];
            }
        }
        cout << deck[0] << endl;
    }
    
    return 0;
}

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

using namespace std;

int main(){

	int n,r;
	int p,c;
	vector<int> dek;
	vector<int>::iterator ite;
	queue<int> tmp;

	while(1){

		cin>>n>>r;
		if(n==0&&r==0) break;

		if(!dek.empty()) dek.clear();
		for(int i=1;i<=n;i++) dek.push_back(i);

		for(int i=0;i<r;i++){
			cin>>p>>c;
			ite=dek.begin();
			advance(ite,n-p-c+1);
			for(int i=0;i<c;i++){
				tmp.push(*ite);
				ite=dek.erase(ite);
			}
			while(!tmp.empty()){
				dek.push_back(tmp.front());
				tmp.pop();
			}
		}
		cout<<dek[n-1]<<endl;
	}

}

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

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

C++: 
#include<bits/stdc++.h>
using namespace std;
int x[100];
int y[100];
int card [100];
int n,r;
int ans[1000];
int counter;
bool input(){
    for(int i=0;i<100;i++){
    x[i]=0;
    y[i]=0;
    }
    cin >>n>>r;
    for(int i=0;i<r;i++){
    cin>>x[i]>>y[i];
    }
    if(n==0){
    return false;
    }
    else{
     return true;
    }
}
void solve(){
    for(int i=0;i<100;i++){
        card[i]=i+1;
    }
    for(int i=0;i<r;i++){
        for(int k=0;k<y[i];k++){
            int a=card[x[i]+y[i]-2];
            for(int j=x[i]+y[i]-1;j>0;j--){
                card[j]=card[j-1];
            }
            card[0]=a;
            
        }
    for(int j=1;j<=y[i]/2;j++){
int remainder=card[j];
card[j]=card[y[i]-j];
card[y[i]-j]=remainder;
}
    }
 
    ans[counter]=card[0];
 counter+=1;
}
  
  
  
int main (){
counter=0
    while(input()){
    solve();
    }
for(int j=0;j<=counter;j++){
cout<<ans[counter]<<endl;
}
return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define ALL(c) (c).begin(), (c).end()
#define dump(a) cerr << #a << "=" << (a) << endl

using namespace std;

int cards[52];

int main() {
	int N,R; 
	int P,C;

	while(cin >> N >> R) {
		if (N == 0 && R == 0) break;
		//初期化
		rep(i,52) {
			cards[i] = 0;			
		}
		rep(i,N) {
			cards[i] = i+1;
		}


		//シャッフル
		vector<int> cards_p,cards_c;
		int center=0;
		rep(r,R) {
			cin >> P >> C;

			//コピー
			center = N-(P-1);
			REP(c,center-C,center) {
				cards_c.push_back(cards[c]);
			}
			REP(p,center,N) {
				cards_p.push_back(cards[p]);
			}
			
			//ペースト
			center = N-C;
			REP(p,center-(P-1),center) {
				cards[p] = cards_p.front();
				cards_p.erase(cards_p.begin());
			}
			REP(c,center,N) {
				cards[c] = cards_c.front();
				cards_c.erase(cards_c.begin());
			}
		}

		cout << cards[N-1] << endl;			
		
	}

	return 0;
}