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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

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

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

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

	deque<int> v;
	for (int i = n; i >= 1; i--) {
	    v.push_back(i);
	}

	int p, c;
	deque<int> w;
	rep(i, r) {
	    cin >> p >> c;
	    p--;
	    for (int j = p; j < p + c; j++) {
		w.push_back(v[j]);
	    }
	    rep(i, c) {
		v.erase(v.begin() + p);
	    }
	    v.insert(v.begin(), all(w));
	    w.clear();
	}

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

    return 0;
}

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

int main(){
	while(1){
		int n,r,p,c;
		cin >> n >> r;
		if(n == 0 && r ==0)break;
		int s[n + 1];
		for(int i = 1; i <= n;++i){
		s[i] = i;
		}
		for(int j = 0; j < r;++j){
			cin >> p >> c;
			if(p == 1)continue;
			for(int k = 0;k < c;++k){
				s[0] = s[n + 2 - p - c];
				for(int l = 0;l < p + c - 2;++l){
					s[n + 2 - p - c + l] = s[n + 3 - p - c + l];
					}
				s[n] = s[0];
			}
		}
		  cout << s[n] << endl;

	}
	return 0;
}

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

int main()
{
  int n,r;
  for(;cin>>n>>r,n;)
    {
      vector<int> a;
      for(int i=n;i>0;i--)
	a.push_back(i);
      for(;r--;)
	{
	  int p,c;
	  cin>>p>>c;
	  vector<int> b;
	  for(int i=0;i<c;i++)
	    {
	      b.push_back(a[p-1]);
	      a.erase(a.begin()+p-1);
	    }
	  for(int i=0;i<a.size();i++)
	      b.push_back(a[i]);
	  a=b;
	}
      cout<<a[0]<<endl;
    }
}

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

int main(){
    int n,r;

    while(cin>>n>>r,n|r){
        vector<int> v(n);

        for(int i=0; i<n;i++){
            v[i]=n-i;
        }

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

            rotate(v.begin(),v.begin()+p-1,v.begin()+p+c-1);
        }

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

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

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

    int n, r, p, c;
    while (true) {
        cin >> n >> r;
        if (n == 0 && r == 0) {
            break;
        }
        vector<int> deck;
        for (int i = 0; i < n; i++) {
            deck.push_back(i + 1);
        }
        for (int i = 0; i < r; i++) {
            cin >> p >> c;
            stack<int> s;
            for (int j = 0; j < c; j++) {
                // cout << "要素番号" << deck.size() - p - j << endl;
                s.push(deck[deck.size() - p - j]);
            }
            // cout << s.top() << endl;
            deck.erase(deck.begin() + (deck.size() - p - c + 1), deck.begin() + (deck.size() - p));
            for (int j = 0; j < c; j++) {
                deck.push_back(s.top());
                s.pop();
            }
        }
        cout << deck[deck.size() - 1] << endl;
    }
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
  int a[51]={};
  int st[51]={};
  int n,r;
  int p,c;
  while(1){
    //in
    cin >> n >> r;
    if(n==0&&r==0)break;
    for(int i=0;i<n;i++){
      a[i]=n-i;
    }
    for(int i=0;i<r;i++){
      cin >> p >>c; 
      for(int j=0;j<n;j++){
	st[j]=a[j];
      }
      for(int j=0;j<c;j++){
	a[j]=st[p-1+j];
      }
      for(int j=c;j<c+p;j++){
	a[j]=st[j-c];
      }
    }
    cout << a[0] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include<vector>
#include<string.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){
    int n,r;
    while(cin>>n>>r,n,r){;
        int card[60];
        for(int i=0;i<60;i++){
            card[i]=n-i;
        }
        for(int i=0;i<r;i++){
            int p,c;
            cin>>p>>c;
            vector<int>C;
            for(int j=0;j<c;j++){
                C.push_back(card[p-1+j]);
            }
            int j;
            for(j=c+p-1;j>=c;j--){
                card[j]=card[j-c];
            }
            for(int k=0;k<c;k++){
                card[k]=C[k];
            }
        }
        cout<<card[0]<<endl;
    }
    return 0;
}

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

int n, r, p, c;
int h[51];

int main() {
  while(cin>>n>>r,n|r) {
    for(int i=0;i<n;++i) {
      h[i] = i;
    }
    for(int i=0; i<r; ++i) {
      cin >> p >> c;
      rotate(h+1, h+p, h+p+c);
    }
    cout << h[1] <<endl;
  }
  return 0;
}

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

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 (input[0][1]==0){											//一回もシャッフルしないならコレ
		return input[0][0];
	}
	else {
		whtop = input[input[0][1]][0];								//一回目のもどしだけ別枠
		input[0][1]--;
		while (input[0][1] != 0) {	
			if (input[input[0][1]][1] < whtop and input[input[0][1]][0] + input[input[0][1]][1] - 1 >= whtop) {
				whtop = whtop - input[input[0][1]][1];
			}
			else whtop = input[input[0][1]][0] + whtop - 1;			//input[input[0][1]][1] >= whtop
			input[0][1]--;
		}
		return input[0][0] - whtop + 1;
	}
}


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

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

int main(){
	while (true){
		int n, r,a[50];
		cin >> n >> r;
		if (n == 0 && r == 0){ break; }
		for (int i = 0; i < n; i++){
			a[i] = n-i;
		}

		for (int i = 0; i < r; i++){
			int p, c, b[50];
			cin >> p >> c;
			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 = 0; j < p-1; j++){
				a[c + j] = b[j];
			}
			cout << a[0] << endl;
		}

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

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)

int main() {
    int n, r;
    while (cin >> n >> r && n) {
        int p, c;
        int a[n];
        rep(i, n) {
            a[i] = n - i;
            //cout << a[i] << " ";
        }
        //cout << endl;
        rep(i, r) {
            cin >> p >> c;
            rotate(a, a + p - 1, a + p + c - 1);
            /*
            rep(i, n) {
                cout << a[i] << " ";
            }
            cout << endl;*/
        }
        cout << a[0] << endl;
    }
}