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<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;

int main(){
  int n,r;
  int p,c;
  int a[100],b[100];

  while(1){
    scanf("%d %d",&n,&r);
    if(n==0 && r==0) break;
    rep(i,n) a[i]=n-i;
    rep(i,r){
      scanf("%d %d",&p,&c);
      rep(j,p+c-1){
        b[j]=a[j];
      }
      rep(j,p-1){
        a[j+c]=b[j];
      }
      rep(j,c) a[j]=b[j+p-1];
    }
    printf("%d\n",a[0]);
  }

  return 0;

}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;

int main(){
	int N,R;
	while(cin>>N>>R,N||R){
		int P,C;
		vector<int> card;
		for(int i=1;i<=N;i++){
			card.push_back(i);
		}
		for(int i=0;i<R;i++){
			cin>>P>>C;
			vector<int>::iterator a,b;
			card.resize(card.size()+C);
			a = card.end()-C-P-C+1; b = card.end()-C-P+1;
			for(int j=0;j<C;j++){
				card[card.size()-(C-j)] = *(a+j);
			}
			card.erase(a,b);
		}
		printf("\t%d\n",card.back());
	}
	return 0;
}

C++: //============================================================================
// Name        : aoj1129.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

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

C++: #include <iostream>

using namespace std;

int main(){
	int n, r;
	int card[50], shuf[50];
	while(cin >> n >> r){
		if(!n) break;
		for(int i=0;i<n;i++) card[i] = n-i;
		for(int i=0;i<r;i++){
			int p, c; cin >> p >> c;
			int j=0;
			for(j=0;j<c;j++) shuf[j] = card[p-1+j];
			for(j=c;j<c+p-1;j++) shuf[j] = card[j-c];
			for(j=c+p-1;j<n;j++) shuf[j] = card[j];
			memcpy(card,shuf,sizeof(card));
		}
		cout << shuf[0] << endl;
	}
}

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

int main(void){
  while(true){
    int n, r;
    cin >> n >> r;
    if(n == 0 && r == 0){ break; }

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

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

int main() {
	int n, r;

	while (cin >> n >> r && n != 0 && r != 0) {
		int card[51];
		for (int i = 1; i <= n; i++) {
			card[i] = n - i + 1;
		}

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

			int temp[50];
			for (int j = 0; j < c; j++) {
				temp[j] = card[p + j];
			}
			for (int j = 1; j < p; j++) {
				card[p + c - j] = card[p - j];
			}
			for (int j = 0; j < c; j++) {
				card[j + 1] = temp[j];
			}
		}
		cout << card[1] << '\n';
	}

	return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>
 
#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
 
const int INF = 10000000;
using namespace std;
typedef long long  ll;
 
/** Problem1129 : Hanafuda Shuffle **/
int main()
{
    vector<int> card;
    int n, r, p, c;
     
    while (cin >> n >> r, n||r) {
        card.clear();
        rep(i, n)
            card.push_back(n-i);
         
        rep(k, r) {
            cin >> p >> c;
            vector<int> tmp;
            rep(i, c)
                tmp.push_back(card[i+p-1]);
            rep(i, p-1)
                tmp.push_back(card[i]);
            REP(i, p+c-1, n) {
                tmp.push_back(card[i]);
            }
            card = tmp;
        }
        cout << card[0] << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int deck[60];
int tmpdeck[60];

int main(){ _;
  int n,r,p,c;
  while(cin>>n>>r,!(n==0&&r==0)){
    REP(i,n) deck[i]=n-i;
    REP(i,r){
      cin>>p>>c;
      p--;
      copy(deck+p,deck+p+c,tmpdeck);
      copy(deck,deck+p,tmpdeck+c);
      copy(tmpdeck,tmpdeck+p+c,deck);
    }
    cout<<deck[0]<<endl;
  }
}

C++: #include <iostream>
#include <list>
#include <cstdlib>

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	int n,r;

	cin >> n;
	cin >> r;

	while (n != 0 || r != 0) {
		std::list<int> lst;
		int now = 1;

		for (int i = 0; i < n; i++) {
			lst.push_back(i+1);
		}

		for (int i = 0; i < r; i++) {
			int index = 1;
			int p,c;
			cin >> p;
			cin >> c;

			for (std::list<int>::iterator itr = lst.begin(); itr != lst.end();) {
				if (index >  n-(p-1)-c && index < n-(p-2) && r != n){
					lst.push_back(*itr);
					itr = lst.erase(itr);
				}else{
					itr++;
				}	
				index++;
			}
		}
		for (std::list<int>::iterator itr = lst.begin(); itr != lst.end(); ++itr) {
			if (now == n) {
				cout << *itr << "\n";
			}
			now++;
		}
		cin >> n;
		cin >> r;
	}	
	return 0;
}

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

int main() {
  while(true) {
    int ncard, r;
    cin >> ncard >> r;
    if(ncard == 0 && r == 0) break;
    vector<int> cards(ncard);
    for(int i = 0; i < ncard; ++i) cards[i] = ncard - i;
    for(int i = 0; i < r; ++i) {
      int p, c;
      vector<int> results;
      cin >> p >> c;
      for(int j = p - 1; j < p - 1 + c; ++j) {
        results.push_back(cards[j]);
      }
      for(int j = 0; j < p - 1; ++j) {
        results.push_back(cards[j]);
      }
      for(int j = p - 1 + c; j < ncard; ++j) {
        results.push_back(cards[j]);
      }
      cards = results;
    }
    cout << cards[0] << endl;
  }
  return 0;
}