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<algorithm>
using namespace std;

int main(){

  int n, r;
  int card[50];

  while(cin>>n>>r, 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, card+p-1, card+p+c-1);
    }

    cout<<card[0]<<endl;
  }

  return 0;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion


int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int n, r;

    while (true) {
        cin >> n >> r;
        if (!n && !r) break;

        vector<int> v(n);
        rep(i, 0, n) v[i] = n - i;

        rep(i, 0, r) {
//            for (int h : v) cout << h << " "; cout << endl;
            int p, r; cin >> p >> r;
            --p;
            vector<int> v2;
            rep(j, p, p + r) v2.push_back(v[j]);
            rep(j, 0, p) v2.push_back(v[j]);
            rep(j, p + r, n) v2.push_back(v[j]);
            v = v2;
        }
//        for (int h : v) cout << h << " "; cout << endl;

        cout << v[0] << endl;
    }
}

C++: #include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<vector>
using namespace std;
int array[51];
int main(){
  int M,N;
  vector<int> v;
  while(cin>>M >>N){
    if(N==0&&M==0){
      break;
    }
    for(int k=0;k<M;k++){//初期化
      array[k]=k+1;
    }
    int p=0,c=0;
    for(int i=0;i<N;i++){
      cin >>p >>c;

      for(int a=0;a<p-1;a++){//上保存
	v.push_back(array[(M-1)-a]);
      }

      for(int t=0;t<c;t++){//下を上へ
	array[(M-1)-t]=array[(M-1)-(p-1)-t];

      }

      for(int l=0;l<p-1;l++){//上を下へ
	array[(M-1)-c-l]=v.front();
	v.erase(v.begin());

      }

      /*
      for(int g=M-1;g>=0;g--){//配列確認
	cout << array[g] <<endl;
	}*/



    }
      cout << array[M-1] <<endl; 
  }
  
  return 0;
}

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

using namespace std;

int main(){
	vector<int> cards;
	vector<int> ::iterator cardsIterator;
	vector<int> ::iterator shuffuleIterator;
	int n,r,p,c;

	while(cin >> n >> r, n && r){
		cards.clear(); //初期化
		// カードの山生成
		for (int i = 0; i < n; ++i){
			cards.push_back(i+1);
		}
		// シャッフル
		while(cin >> p >> c, r--){
			cardsIterator = cards.end();
			cardsIterator -= p + (c - 1);
			while(c--){
				cards.push_back(*cardsIterator);
				cards.erase(cardsIterator);
			}
			if (r == 0){
				break;
			}
		}
		// 一番上のカード表示
		cout << cards.back() << endl;
	}
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);

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

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

using namespace std;

long long INF=1e15;

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

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

        vector<int> a(n);
        for(int i=0;i<n;i++)a[i]=n-i;

        for(int i=0;i<r;i++){
            int p,c;
            cin>>p>>c;
            vector<int> b(p);
            for(int j=0;j<p-1;j++)b[j]=a[j];
            for(int j=0;j<c;j++)a[j]=a[p+j-1];
            for(int j=c;j<c+p-1;j++)a[j]=b[j-c];
        }
        cout<<a[0]<<endl;
    }
}

C++: #include<stdio.h>
int main(void){
	int p, c, count, n, r, huda[200] = {0}, i, j;
	while (1) {
		scanf("%d %d", &n, &r);
		for (i = 0;i < n;i++) {
			huda[i] = i + 1;
		}
		if (n == 0 && r == 0) {
			break;
		}
		for (i = 0;i < r;i++) {
			scanf("%d %d", &p, &c);

			for (j = 0;j < c;j++) {
				huda[n + j] = huda[n - p+j];
				huda[n - p+j] = -1;
			}

			count = 0;
			for (j = 0;j < n;j++) {

				if (count > n)
					break;
				huda[j] = huda[count];
				if (huda[count] == -1) {
					j--;
				}
				count++;

			}
		/*	for (j = 0;j < n;j++) {
				printf("%d ", huda[j]);
			}*/
		}
		printf("%d\n",huda[n-1]);
	}


	return 0;
}

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

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

using namespace std;

typedef vector<int> vi;

void pp(vi v){
	rep(i, v.size()){
		cout << v[i] << ' ';
	}
	cout << endl;
}

int main(){
	int n, r;

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

		if(!n && !r) break;

		n++;
		vi cards(n);
		rep(i, n){
			cards[i] = i;
		}

		int p, c;
		rep(i, r){
			cin >> p >> c;

			int index = n-(p-1+c);

			vi pick;
			// cardsの後ろからp-1+c番目からc個を保管
			rep(j,c){
				pick.push_back(cards[index+j]);
			}
		
			// cardsの後ろからp-1+c番目にp1番目-0をコピー
			rep(j, p-1){
				cards[index+j] = cards[index+j+c];
			}

			// 保管していたのを後ろに追加
			rep(j,c){
				cards[index+p-1+j] = pick[j];
			}

			//pp(cards);
		}
		cout << cards[n-1] << endl;
	}

	return 0;
}