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 C[51];
    int n, r; //カードの枚数、シャッフル回数
    int p, c; //山の一番上からp枚目の札から連続したc枚の札を抜き山の上にそのまま置く
    while(true){
        cin >> n >> r;
        if(n + r == 0) break;

        //山全体の構成
        for(int i = 0; i < n; i++){
            C[i] = n - i;
        }
        // for(int i = 0 ; i < n; i++){
        //     cout << C[i] << endl;
        // }


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

            //シャッフルする
            rotate(C, C + p - 1, C + p - 1 + c);
            // for(int i = 0; i < n; i++){
            //     cout << C[i] << endl;
            // }  
        }
        cout << C[0] << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

int main(){
    int n, r, p, c;

    while(true){
        stack<int> x;
        cin >> n >> r;
        if(n == 0 && r == 0) break;

        for(int i=1; i<=n; i++){
            x.push(i);
        }

        for(int i=0; i<r; i++){
            stack<int> pp, cc;
            cin >> p >> c;
            for(int i=0; i<p-1; i++){
                pp.push(x.top());
                x.pop();
            }
            
            for(int i=0; i<c; i++){
                cc.push(x.top());
                x.pop();
            }

            for(int i=0; i<p-1; i++){
                x.push(pp.top());
                pp.pop();
            }
            for(int i=0; i<c; i++){
                x.push(cc.top());
                cc.pop();
            }
        }

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

    return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <iterator>
#include <iostream>
#define MAX_CARD 51
using namespace std;

int main(void) {
	int n, r;
	for (;;) {
		cin >> n >> r;
		if (n == 0 && r == 0) {
			break;
		}
		vector<int> card;
		for (int i = n; i > 0; i--) {
			card.push_back(i);
		}

		for (int i = 0; i < r; i++) {
			int p, c;
			cin >> p >> c;
			vector<int> buf;
			for (int i = p - 1; i < p + c - 1; i++) {
				buf.push_back(card[i]);
				// printf("%d\n", card[i]);
			}

			for (int i = 0, j = buf.size(); i < p - 1; i++, j++) {
				buf.push_back(card[i]);
				// printf("%d\n", card[i]);
			}

			for (int i = p + c - 1, j = buf.size(); i < card.size(); i++, j++) {
				buf.push_back(card[i]);
				// printf("%d\n", card[i]);
			}

			for (int i = 0; i < card.size(); i++) {
				card[i] = buf[i];
				//printf("%d\n", card[i]);
			}
			//printf("\n");

			// shuffle(card, p, c);
		}
		printf("%d\n", card[0]);
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
int main() {
	cin.tie(); ios::sync_with_stdio(false);
	int n, r;
	while (true) {
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		vector<int> card(n);
		iota(card.rbegin(), card.rend(), 1);

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

C++: #include <bits/stdc++.h>
using namespace std;
int A[100], B[100], C[100];

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

C++: #include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

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

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
  int n,r,p,c;
  vector<int> ans;
  while(cin >> n,n){
    cin >> r;
    vector<int> v,q;
    for(int i = n;i > 0;i--)v.push_back(i);
    for(int i = 0;i < r;i++){
      cin >> p >> c;
      for(int j = 0;j < p - 1;j++)q.push_back(v[j]);
      for(int j = p - 1;j < p + c - 1;j++)v[j - p + 1] = v[j];
      for(int j = c;j < p + c - 1;j++)v[j] = q[j - c];
    }
    ans.push_back(v[0]);
  }
  for(int i = 0;i < ans.size();i++)cout << ans[i] << endl;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 52;
int before[MAXN], after[MAXN];

int main()
{
    int n, r, p, c;
    while(cin >> n >> r && (n && r))
    {
        for(int i = n; i > 0;i--) before[n - i] = i;

        REP(r)
        {
            cin >> p >> c;

            rep(j,p - 1) after[c + j] = before[j];
            rep(j,c) after[j] = before[p - 1 + j];
            rep(j,MAXN) before[j] = after[j];
        }
        cout << before[0] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
const double PI=acos(-1.0);
//---------------------------------------------------------------------------//
int n,r,p1,c;
int huda[51],huda2[51];
int main(){
        while(1) {
                cin>>n>>r;
                if(n==0 && r==0) {
                        return 0;
                }
                for(int i=0; i<n; i++) {
                        huda[i]=n-i;
                        huda2[i]=huda[i];
                }
                for(int i=0; i<r; i++) {
                        cin>>p1>>c;
                        for(int j=0; j<c; j++) {
                                huda[j]=huda[p1-1+j];
                        }
                        for(int j=0; j<p1-1; j++) {
                                huda[c+j]=huda2[j];
                        }
                        for(int j=0; j<51; j++) {
                                huda2[j]=huda[j];
                        }
                }
                cout<<huda[0]<<endl;
        }
}