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 <queue>
#include <stack>
#include <vector>
#include <stdio.h>
using namespace std;

int main(){
	int n=1,r=1;
	int i,j;
	int c,p;
	cin>>n>>r;
	while(!(n==0&&r==0)){
		int x[100];
		queue<int> q;
	
	//cout<<n<<" "<<r<<endl;
	for(i=1;i<=n;i++){
		x[i] = i;
	}
	for(i=0;i<r;i++){
		cin>>p>>c;
		for(j=0;j<c;j++){
			q.push(x[n-p+1-j]);
		}
		for(j=0;j<p-1;j++){
			q.push(x[n-j]);
		}
		for(j=0;j<p+c-1;j++){
			x[n-j]=q.front();
			//cout<<q.front()<<endl;
			q.pop();
		}
	}
	cout<<x[n]<<endl;
		/*for(i=1;i<=n;i++){
			printf("%d\n",x[i]);
		}*/
		cin>>n>>r;
	}
	return 0;
}

C++: 
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	while(1) {
		int n, r, p, c;
		vector<int> cards;	//山札を意味するvector

		cin >> n >> r;		//山の枚数とシャッフル回数を取得する

		for(int i = n; i > 0; i --)
			cards.push_back(i);

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

		for(int i = 0; i < r; i++) {
			cin >> p >> c;
			vector<int> tmp;	//抜き取った札を一時的に記憶するvector

			//c枚の札を抜き取る
			for(int j = 0; j < c; j++)  
				tmp.push_back(cards.at(p - 1 + j));

			//p-1枚の札を下に移す
			for(int j = p - 2; j >= 0; j--)	
				cards.at(j + c) = cards.at(j);

			//c枚の札を上に戻す
			for(int j = 0; j < c; j++) 
				cards.at(j) = tmp.at(j);
		}

		//答えの出力
		cout << cards.at(0) << endl;
	}

	//while(1){}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    while(true){
        int n,r; cin>>n>>r;
        if(n==0&&r==0)break;
        
        vector<int> a(n);
        REP(i,n)a[i]=i+1;
        reverse(a.begin(),a.end());
        
        REP(kai,r){
            stack<int> sta;
            int p,c; cin>>p>>c;
            REP(i,c)sta.push(a[i+p-1]);
            REP(i,c)a.erase(a.begin()+p-1);
            REP(i,c){
                a.insert(a.begin(),sta.top());
                sta.pop();
            }
            /*REP(i,a.size())cout<<a[i]<<" ";
            cout<<endl;*/
        }
        
        cout<<a[0]<<endl;
        
    }
    
    return 0;
}

C++: #include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

using ll = long long;
#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()
int main(){
    int n, r;
    while(true){
        cin >> n >> r;
        if(n == 0 && r == 0) break;
        int p[r], c[r];
        rep(i, r) cin >> p[i] >> c[i];
        map<int, int> mp;
        for(int i = 1; i <= n; i++) mp[i] =  n + 1 - i;
        rep(i, r){
            const int P = p[i], C = c[i];
            int A[P + 1] = {0}, B[C + 1] = {0};
            loop(i, 1,  P) A[i] = mp[i];
            loop(i, 1 , C + 1) B[i] = mp[i + P - 1];
            loop(i, 1,  P + C){
                if(i <= C) mp[i] = B[i];
                else mp[i] = A[i - C];
            }
        }
        cout << mp[1] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define N_PRIME 1000000007
#define ll int64_t

bool loop(){
    int n,r;
    cin >> n >> r;
    vector<int> a;
    
    for(int i = 0 ; i < n ; i++ ){
        a.push_back(i+1);
    }
    if( n == 0 && r == 0 )return false;
    
    for(int i = 0 ; i < r; i++ ){
        int p,c;
        cin >> p >> c;
        p = n + 1 - (c+p);
        for(int j = 0 ; j < c ; j++ ){
            a.push_back(a[p]);
            a.erase(a.begin() + p);
        }
        /*
        for(int j = 0 ; j < n ; j ++ ){
            cout << a[j] << "\t";
        }
        cout << endl;*/
    }
    
    cout << a[n-1] << endl;
    
    return true;
}


int main(void){
    while(loop());
    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 (int i = 0; i < r; i++) {
			cin >> p >> c;

			p = n - p - c + 1;
			for (int j = 0; j < c; j++) {
				cards.push_back(cards[p]);
				cout << "cards[p]=" << cards[p] << endl;
				cards.erase(cards.begin() + p);
			}
		}

		cout << cards.back() << '\n';
	}

	return 0;
}

C++: 
#include<cstdio>
#include<iostream>
#include<string>
#include <algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<set>
using namespace std;
using ll = long long;

int n, r, a, b;
int t[100];
int u[100], size;
int main() {
	while (cin >> n >> r && n&&r) {
		for (int i = 0; i<n; i++)t[i] = n - i;
		for (int i = 0; i<r; i++) {
			cin >> a >> b;
			for (int j = 0; j<b; j++)u[j] = t[j + a - 1];
			for (int j = a - 2; j >= 0; j--)t[j + b] = t[j];
			for (int j = 0; j<b; j++)t[j] = u[j];
		}
		cout << t[0] << endl;
	}
	return 0;
}

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

using namespace std;

int N, R, p, c, i, j;
int A[N] = {};

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

C++: #include <iostream>
using std::cin;
using std::cout;
using std::endl;

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

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

int main(){
int n;
int r;
cin >> n >> r;
while (n!=0 || r!=0){
vector<int> card(n+1);
for (int i = 0; i < n; i++){
card[i]=n-i;
}
for (int i = 0; i < r; i++){
int p;
int c;
cin >> p >> c;
for (int j = 0; j < c; j++){
int deletenumber;
deletenumber = card[c+p-2];
card.erase(card.begin() + c+p-2);
card.insert(card.begin(),deletenumber);
}
}
cout << card[0] << endl;
cin >> n >> r;
}
}