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<stdio.h>

int main(){
    while(1){
        int n,r;
        int table[50];
        scanf("%d%d", &n, &r);
        if(n == 0 && r==0){
            return 0;
        }
        for (int i=0; i<n ; i++) {
            table[i]=n-i;
        }
        for(int i=0; i<r; i++){
            int p,c;
            int work[50];
            scanf("%d%d", &p,&c );
            for(int j=0; j<c; j++){
                work[j]=table[p-1+j];
            }
            for(int j=0; j<p-1; j++){
                work[c+j]=table[j];
            }
            for(int j=p-1+c; j<n; j++){
                work[j]=table[j];
            }
            for(int j=0; j<n; j++){
                table[j]=work[j];
            }
        }
        printf("%d\n", table[0] );
    }
}

C++: #include<iostream>
using namespace std;
int main(){

  int n, r, p, c, d[50], e[50];

  while(cin >> n >> r && n && r){
    for(int i=0; i<n; i++)
      d[i] = n - i;
      for(int i=0; i<r; i++){
        cin >> p >> c;
        for(int j=0; j<p-1; j++)
          e[j] = d[j];
          for(int j=0; j<c; j++)
          d[j] = d[j+p-1];
          for(int j=0; j<p-1; j++)
          d[j+c] = e[j];
      }
      cout << d[0] << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;

int main(){

	int n,r,c,p,ar[50];
	while(cin>>n>>r){
		if(n==0 && r==0) return 0;
		for(int i=0; i<n; i++) ar[i]=n-i;
		for(int i=0; i<r; i++){
			cin>>p>>c;
			int t1[50],t2[50];
			for(int i=0; i<p-1; i++){
				t1[i] = ar[i];
			}
			for(int i=p-1; i<p+c-1; i++){
				t2[i-p+1] = ar[i];
			}
			for(int i=0; i<c; i++){
				ar[i]=t2[i];
			}
			for(int i=c; i<p+c-1; i++){
				ar[i]=t1[i-c];
			}
		}
		cout<<ar[0]<<endl;
	}

	return 0;
}

C++: #include<iostream>

#define R input[0][1]

using namespace std;

int input() {
	int input[51][2];
	cin >> input[0][0] >> input[0][1];								//まずnとr
	if (input[0][0] == 0 && input[0][1] == 0) {
		return 0;
	}
	for (char pos = 1; pos <= input[0][1]; pos++) {					//r回のシャッフルの仕方を入力
		cin >> input[pos][0] >> input[pos][1];
	}																//ここまで入力

	/*シャッフルもどし*/
	int whtop = 1;													//最後一番上にいるカードは、今何番目にいる？
	if (R==0)return input[0][0];									//一回もシャッフルしないならコレ
	while (input[0][1] != 0) {	
		if (whtop <= input[R][1]) whtop = whtop + input[R][0] - 1;
		else if ((input[R][0] + input[R][1] - 1) < whtop) whtop = whtop;
		else whtop = whtop - input[R][1];
		R--;
	}
	return input[0][0] - whtop + 1;

}


int main()
{
	while (1) {
		int check;
		check = input();
		if (check == 0)break;
		else cout << check << endl;
	}
}

C++: #include <iostream>
#include<bits/stdc++.h>
using namespace std;
int n,m,a,b;
vector<int> v,u;
int main(void){
    while(1){
    cin>>n>>m;
    if(n==0&&m==0)return 0;
    for(int i=n;i>0;i--){
        v.push_back(i);
    }
    for(int i=0;i<m;i++){
        cin>>a>>b;
        a--;
        for(int i=n-1;i>a+b-1;i--)u.push_back(v[i]);
        for(int i=a-1;i>=0;i--)u.push_back(v[i]);
        for(int i=a+b-1;i>=a;i--)u.push_back(v[i]);
        v={};
        for(int i=n-1;i>=0;i--)v.push_back(u[i]);
        u={};
    }
    cout<<v[0]<<endl;
    v={};
    }
}

C++: #include <stdio.h>
#include <iostream>

using namespace std;

void suffle (int a, int b, int t[]) {
	int kari[50];
	int kari2[50];
	for (int i = 0; i < a-1; i++) {
		kari[i] = t[i];
	}
	for (int i = 0; i < b; i++) {
		kari2[i] = t[a-1+i];
	}

	for (int i = 0; i < b; i++) {
		t[i] = kari2[i];
	}

	for (int i = 0; i < a-1; i++) {
		t[b+i] = kari[i];
	}
	return;
}

int main() {
	int yama[50];
	int k,r;
	int a,b;

	while (cin >> k >> r) {
		if (k == 0 && r == 0) {
			break;
		}

		for (int i = 0; i < k; i++) {
			yama[i] = k-i;
		}

		for (int i = 0; i < r; i++) {
			cin >> a >> b;
			suffle(a,b,yama);
		}
		cout << yama[0] << endl;
	}
	return 0;
}

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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

signed main(){
    while(true){
        int n, r; cin >> n >> r;
        if(n == 0)break;
        vector<int> l(n+1);
        for(int i = 1; i <= n; i++){
            l[i] = i;
        }
        for(int i = 0; i < r; i++){
            int p,c; cin >> p >> c;
            int b = n-p-c+2;
            for(int j = 0; j < c; j++){
                l.push_back(l[b]);
                l.erase(l.begin() + b);
            }
        }
        cout << l.back() << endl;
    }

    return 0;
}

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int n,r;
	while(true){
		cin >> n >> r;
		if(!n&&!r) break;
		vector<int> fuda;
		REP(i,n) fuda.push_back(i+1);
		REP(i,r){
			int p, c;
			cin >> p >> c;
			for(int j=c-1;j>=0;j--){
				fuda.push_back(fuda[n-p-j]);
			}

			for(int j=0;j<c;j++){
				fuda.erase(fuda.begin());
			}
		}
		cout << fuda[n] << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
ll MIN(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}//pは素数,aのb乗をpで割った余り
ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}//pは素数,(nCr)%p
ll gcd(ll a, ll b) {

	if (a < b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	if (a%b == 0)return b;
	return gcd(b, a%b);

}//最大公約数
ll lcm(ll a, ll b) {

	return a / gcd(a, b)*b;

}//最小公倍数

int main() {
	
	while(1){
		int N,R;
		cin>>N>>R;
		if(N==0&&R==0)break;
		vector<int> V;
		for(int i=0;i<N;i++){
			V.pb(N-i);
		}
		for(int i=0;i<R;i++){
			int p,c;
			cin>>p>>c;
			vector<int> tmp;
			for(int j=0;j<c;j++){
				tmp.pb(V[p-1+j]);
			}
			for(int j=0;j<p-1;j++){
				tmp.pb(V[j]);
			}
			for(int j=0;j<N-(p-1)-c;j++){
				tmp.pb(V[p-1+c+j]);
			}
			V=tmp;
		}
		cout<<V[0]<<endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main(){
  int n,r;
  while(1){
    cin >> n >> r;
    if(n==0&&r==0)break;
    int p,c;
    vector<int> bef(n);
    vector<int> aft(n);
    rep(i,n){
      bef[i] = n-i;
    }
    rep(i,r){
      cin >> p >> c;
      for(int j=0;j<c;j++){
        aft[j]=bef[p-1+j];
      }
      for(int j=0;j<p-1;j++){
        aft[c+j]=bef[j];
      }
      for(int j=c+p-1;j<n;j++){
        aft[j]=bef[j];
      }
      bef=aft;
    }
    cout << bef[0] << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int card[50];
int buffer[50];
int main()
{
	int n,r;
	while(cin>>n>>r,n!=0){
		for(int i=0;i<n;i++)card[i]=i+1;
		for(int i=0;i<r;i++){
			int p,c;
			cin>>p>>c;
			for(int j=0;j<p-1;j++)
				buffer[j]=card[j];
			for(int j=0;j<c;j++)
				card[j]=card[j+p-1];
			for(int j=0;j<p-1;j++)
				card[j+c-1]=buffer[j];
		}
		cout<<card[0]<<endl;
	}
	return 0;
}