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;
  while(cin >> n >> r, n){
    int npos[100];
    for(int i=n-1,j=0;i>=0;i--,j++){
      npos[j] = i+1;
    }
    for(int i=0;i<r;i++){
      int a,b;
      cin >> a >> b;
      int tmp[b];
      for(int j=0;j<b;j++){
	tmp[j] = npos[j+a-1];
      }
      for(int j=a+b-2;j>=b;j--){
	npos[j] = npos[j-b];
      }
      for(int j=0;j<b;j++){
	npos[j] = tmp[j];
      }
    }
    cout << npos[0] << endl;
  }
}

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

int main(){
  int n,r;
  int p,c;
  while(true){
    cin >> n >> r;
    if(n == 0 && r == 0) break;
    int cards[n];
    int result[n];
    for(int index=0;index<n;index++){
      cards[index] = n - index;
    }
    for(int i=0;i<r;i++){
      cin >> p >> c;
      for(int j=0;j<n;j++){
        if(j < c){
          result[j] = cards[p-1+j];
        }else if(j < c + p - 1){
          result[j] = cards[j-c];
        }else{
          result[j] = cards[j];
        }
      }
      for(int k=0;k<n;k++) cards[k] = result[k];
    }
    cout << cards[0];
    cout << endl;
  }
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define fi first
#define se second
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

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

    int n, r;
    cin >> n >> r;
    while(!(n==0 && r==0)){
        vector<int> a(n);
        REP(i, n) a[i] = n-i;
        REP(i, r){
            int p, c;
            cin >> p >> c;
            p--;
            vector<int> a_cp(a);
            REP(i, n){
                if(i < c) a_cp[i] = a[p+i];
                else if(i < c+p) a_cp[i] = a[i-c];
                else a_cp[i] = a[i];
            }
            copy(All(a_cp), a.begin());
        }
        cout << a[0] << "\n";
        cin >> n >> r;
    }
    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <cstring>

using namespace std;
const int INF = (1<<30);
typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for (int i = 0; i < a; i++)

int sx, sy;

int gx, gy;

int qqq;

//各座標までの最短距離
int d[100][100];


//移動方向のベクトル
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

//汎用
ll ans = 0;
pair<int, int> red[101], blue[101];
ll BIG = 10000000000;

//累乗
ll POW(ll a, ll b) {
ll c = 1;
for (int i = 0; i < b; ++i) {
c *= a;
}
return c;
}

//階乗
int Kaijou(int a) {
if (a < 2) return 1;
return a * Kaijou(a - 1);
}


int A[200000];
int kinds[200001];


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

		vector<int> s(n);
		iota(s.begin(), s.end(), 1);
		reverse(s.begin(), s.end());

		rep(i, r) {
			int p, c;
			cin >> p >> c;
			int toU[100] = { 0 }, toD[100] = { 0 };
			rep(i, c) {
				toU[i] = s[p - 1 + i];
			}
			rep(i, p - 1) {
				toD[i] = s[i];
			}
			rep(i, c) {
				s[i] = toU[i];
			}
			rep(i, p - 1) {
				s[i + c] = toD[i];
			}
		}
	
		cout << s[0] << endl;
	}
	cin >> qqq;
}

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

using namespace std;

int main(void)
{
	int n, r;
	while(cin >> n >> r, n > 0){
		vector<int> card(n);
		//カード番号初期化
		for(int i=0;i<n;i++){
			card[i] = n-i;
		}
		//シャッフル処理
		for(int i=0;i<r;i++){
			int p, c;
			cin >> p >> c;
			rotate(card.begin(), card.begin()+p-1, card.begin()+p+c-1);
		}
		cout << card[0] << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,r,i,p,c,v;
  int array[100];
  int box[100];
  while(1){
    cin>>n>>r;
   
    if(n==0&&r==0) break;
    else{
      for(i=0;i<n;i++){
	box[i]=i+1;
      }
     
      for(i=0;i<r;i++){
	v=i;
	cin>>p>>c;
	for(i=0;i<c;i++){
	  array[i]=box[n-p-i];
	 
	}
	for(i=0;i<p-1;i++){
	 box[n-p-c+1+i]=box[n-p+1+i];
	  
	}
	for(i=0;i<c;i++){
	  box[n-1-i]=array[i];
	  
	}
	i=v;
      }
	cout<<box[n-1]<<endl;

    }
  }
  return 0;
}

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

int main(void) {
	int N, R;
	while (cin >> N >> R, N) {
		if (N == 1){
			cout << 1 << endl;
			continue;
		}
		
		stack<int> yama;
		for (int i = 1; i <= N; i++) {
			yama.push(i);
		}

		for (int i = 0; i < R; i++) {
			stack<int> p;
			stack<int> c;
			int begin, size;
			cin >> begin >> size;

			for (int j = 0; j < begin - 1; j++) {
				p.push( yama.top() );
				yama.pop();
			}
			for (int j = 0; j < size; j++) {
				c.push ( yama.top() );
				yama.pop();
			}

			while (!p.empty()) {
				yama.push( p.top() );
				p.pop();
			}
			while (!c.empty()) {
				yama.push( c.top() );
				c.pop();
			}
		}

		cout << yama.top() << endl << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
const ll mod = 1e9 + 7;

int main() {
	cin.sync_with_stdio(false);
	int n,r;
	vector<int>ans;
	while (1) {
		cin >> n >> r;
		if (n == 0 && r == 0)break;
		vector<int>b(n), a(n);
		int p, c;
		rep(i, n)b[i] = n-i;
		rep(i, r) {
			cin >> p >> c;
			rep(j, c)a[j] = b[p - 1 + j];
			rep(j, p-1)a[c + j] = b[j];
			reps(j, p + c - 1, n)a[j] = b[j];
			rep(j, n)b[j] = a[j];			
		}
		ans.push_back(a[0]);

	}
	for (auto x : ans)cout << x << endl;
	return 0;
}

C++: #include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
struct ml{
  int dt;
  struct ml *nx;
};
typedef struct ml Ml;
void f(Ml *a,int p,int q){
  int i;
  Ml *b,*c,*d;
  b=a;
  for(i=0;i<p-1;i++)
    b=b->nx;
  c=b;
  for(i=0;i<q;i++)
    c=c->nx;
  d=a->nx;
  a->nx=b->nx;
  b->nx=c->nx;
  c->nx=d;
  return;
}
int main(){
  int i;
  int n,r,p,q;
  Ml *a;
  while(cin>>n>>r&&n+r){
    a=(Ml*)malloc((n+2)*sizeof(Ml));
    for(i=0;i<n+1;i++){
      (a+i)->dt=n-i+1;
      (a+i)->nx=a+i+1;
    }
    (a+i)->dt=n-i+1;
    for(i=0;i<r;i++){
      cin>>p>>q;
      if(p!=1)
	f(a,p,q);
    }
    cout<<a->nx->dt<<endl;
    free(a);
  }
  return 0;
}

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

int n,r;

int main(){

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


for (int i = r; i >=1; i--){

		cin >> p >> c;

		int M[p-1];
		int N[c];
for (int i = 0; i <= p-2; i++){
			M[i] = A[i];
		}
for (int i = 0; i <= c-1; i++){
			N[i] = A[p-1+i];
		}
		//??????
for (int i = 0; i <= c-1; i++){
			A[i]  = N[i];
		}
for (int i = 0; i <= p-2; i++){
			A[c+i]  = M[i];
		}
		if(i == 1){
			cout << A[0] << endl;
		}

	}
  }
}