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 REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v),end()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;

template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}
//-----------------------------------------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    while(true)
    {
        int n,r,A[50];
        cin>>n>>r;
        if(n==0 && r==0) break;

        REP(i,n) A[i]=n-i;
        REP(i,r){
            int p,c;
            vector<int> v;
            cin>>p>>c;
            p--;
            for(int i=p;i<p+c;i++) v.pb(A[i]);
            for(int i=0;i<p;i++) v.pb(A[i]);
            for(int i=p+c;i<n;i++) v.pb(A[i]);
            REP(i,n) A[i]=v[i];
        }
        cout<<A[0]<<endl;

    }
}

C++: 
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1129&lang=jp

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#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;

vector<int> cut(vector<int> yama, int p, int c)
{
	int n = yama.size();
	vector<int> tmp;

	rep(i,c){
		int index = n-p;
		tmp.push_back(yama[index-i]);
	}

	reverse(ALL(tmp));

	rep(i,c){
		int index = n-p-i;	
		yama.erase(yama.begin()+index);
	}

	yama.insert(yama.end(),ALL(tmp));

	return yama;
}

int main() {
	int N,R;

	while(cin >> N >> R && N && R)
	{
		vector<int> yama;
		REP(i,1,N+1){ yama.push_back(i); }

		int P,C;
		rep(i,R)
		{
			cin >> P >> C;
			yama = cut(yama, P, C);
		}
		cout << yama[yama.size()-1] << endl;
	}
	return 0;
}

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

using namespace std;

int32_t main()
{
  while(true){
    uint32_t n, r;
    cin >> n >> r;
    if(n == 0) break;

    vector<uint32_t> cards(51, 0);
    for(int32_t i = n-1, j = 1;  i >= 0; i--, j++){
      cards[i] = j;
    }

    for(uint32_t i = 0; i < r; i ++){
      uint32_t p, c;
      cin >> p >> c;
      vector<uint32_t> cs;
      for(uint32_t i = p - 1; i < p - 1 + c; i++){
        cs.push_back(cards[i]);
      }
      for(uint32_t i = 0; i < p - 1; i++){
        cs.push_back(cards[i]);
      }
      for(uint32_t i = p - 1 + c - 1; i < n; i++){
        cs.push_back(cards[i]);
      }
    }

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

C++: #include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> PII;

int main()
{
	int n, r;
	while (cin >> n >> r, n || r) {
		vector<PII> shuffles;
		for (int i = 0; i < r; ++i) {
			int p, c;
			cin >> p >> c;
			shuffles.push_back(make_pair(p, c));
		}
		reverse(shuffles.begin(), shuffles.end());
		int index = 0;
		for (int i = 0; i < shuffles.size(); ++i) {
			int p = shuffles[i].first, c = shuffles[i].second;
			if (index < c) {
				index += p - 1;
			} else if (index < c + p - 1) {
				index -= c;
			}
		}
		cout << n - index << endl;
	}
}

C++: #include <iostream>
#include <queue>
#define INF (2<<29)
using namespace std;

typedef struct _node {
    _node* next;
    int n;
} Node;

Node* h;
int n,r,p,c;

Node* initNode(){
    Node* head = (Node*)malloc(sizeof(Node));
    head->n = n;
    Node* bef;
    bef = head;
    for(int i = n-1; i >= 1; i--){
        Node* tmp = (Node*)malloc(sizeof(Node));
        tmp->n = i;
        bef->next = tmp;
        bef = tmp;
    }
    return head;
}

void freeNode(Node* n){
    if(n->next != NULL) freeNode(n->next);
    free(n);
}

void pc(){
    Node *n1,*n2,*n3,*n4;
    // cout<<"[INFO]SHUFFLE-BEGIN"<<endl;
    if(p==1 && c==n) return;
    n1 = h;
    for(int i = 0; i < p-2; i++){ //p-1??????=n1
        n1 = n1->next;
    }
    n2 = n1->next; //p??????=n2
    
    // cout<<"p = "<<n2->n<<endl;
    
    n3 = n1;
    for(int i = 0; i < c; i++){ //p+c??????=n3
        n3 = n3->next;
        // cout<<"hoge"<<endl;
    }
    n4 = n3->next;
    n1->next = n4;
    n3->next = h;
    h = n2; //head???n2???
    // cout<<"[INFO]SHUFFLE-END"<<endl;
}

int main(void){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    for(;;){
        cin>>n>>r;
        if(n==0 && r==0) break;
        h = initNode();
        for(int i = 0; i < r; i++){
            cin>>p>>c;
            // cout << "p=" << p << ",c=" << c << endl;
            pc();
        }
        cout<<h->n<<endl;
        // cout<<"??????"<<endl;
    }

    return 0;
}

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

void hanafuda_set(vector<int>& ary,int& n);
void hanafuda_shuffle(vector<int>& ary,int& r);

int main()
{
	int n;	//山の枚数
	int r;	//カット操作の回数

	vector<int> ary;	//山札

	while(true)
	{
		cin>>n>>r;

		//終了
		if(n==0 && r==0)	break;

		//山札セット
		hanafuda_set(ary,n);

		//山札シャッフル
		hanafuda_shuffle(ary,r);

		//山の一番上の札を出力
		cout<<ary[0]<<endl;		

		//山札の初期化
		ary.clear();
	}
}

//山札セット関数
void hanafuda_set(vector<int>& ary,int& n)
{
	for(int i=n;i>>0;i--)
	{
		ary.push_back(i);
	}
}

//山札シャッフル関数
void hanafuda_shuffle(vector<int>& ary,int& r)
{
	int p;		//p番目の札から
	int c;		//c枚の札を抜き取る
	vector<int> tmp;	//退避配列

	for(int i=0;i<r;i++)
	{
		cin>>p>>c;
		
		//カット内容記録および消去
		for(int j=0;j<c;j++)
		{
			vector<int>::iterator it = ary.begin();
			tmp.push_back(ary[p-1]);
			ary.erase(it+(p-1));
		}
		//一番上に挿入
		for(int j=c;j>0;j--)
		{
			vector<int>::iterator it = ary.begin();
			ary.insert(it,tmp[j-1]);
		}
		//退避内容クリア
		tmp.clear();
	}
}

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





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

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

using namespace std;

int main()
{
    while (true) {
        int n;
        int r;
        cin >> n >> r;

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

        vector<int> v(static_cast<size_t>(n));
        iota(begin(v), end(v), 1);
        reverse(begin(v), end(v));
        for (int i = 0; i < r; ++i) {
            int p;
            int c;
            cin >> p >> c;
            vector<int> t;
            copy_n(begin(v) + (p - 1), c, back_inserter(t));
            copy_n(begin(v), (p - 1), back_inserter(t));
            copy(begin(v) + (p - 1) + c, end(v), back_inserter(t));
            v = t;
        }
        cout << v[0] << endl;
    }
}