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(){
	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];
				cout << 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 <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n,r;
    for(;;){
        scanf("%d%d",&n,&r);
        if(n==0 && r==0) break;
        int p,c;
        vector<int> ca(n);
        for(int i=0;i<n;i++){
            ca[i]=n-i;
        }
        for(int i=0;i<r;i++){
            scanf("%d%d",&p,&c);
            rotate(begin(ca),begin(ca)+p-1,begin(ca)+p-1+c);
        }
        printf("%d\n",ca[0]);
    }
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define REP(i,k,n) for(int i = k; i < n; i++)

#define vi vector<int>
#define pb push_back
using namespace std;

int main(){
    int n,r,p,c;
    vi v(51,0);
    vi t(51,0);
    while(cin >> n >> r,n != 0) {
        rep(i,n) v[i] = n - i;
        rep(i,r){
            cin >> p >> c;
            rep(j,c) t[j] = v[p - 1 + j];
            rrep(j,p) v[j + c - 1] = v[j - 1];
            rep(j,c) v[j] = t[j];
        }
        cout << v[0] << endl;
    }
    return 0;

}

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

#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];									//一回もシャッフルしないならコレ

	whtop = input[input[0][1]][0];									//一回目のもどしだけ別枠
	R--;
	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>
using namespace std;

int input() {
	int input[51][2];
	cin >> input[0][0] >> input[0][1];								
	if (input[0][0] == 0 && input[0][1] == 0) {
		return 0;
	}
	for (char pos = 1; pos <= input[0][1]; pos++) {
		cin >> input[pos][0] >> input[pos][1];
	}																


	int whtop = 1;													
	whtop = input[input[0][1]][0];
	input[0][1]--;
	while (input[0][1] != 0) {

		if (input[input[0][1]][1] >= whtop) {
			whtop = input[input[0][1]][0] + whtop - 1;
		}
		else {
			whtop = whtop - input[input[0][1]][1];
		}
		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<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int n,r;
  int p,c;
  while(1){
    cin >> n >> r;
    if(n == 0) break;
    vector<int> A(n);
    for(int i = 0; i< n; i++){
      A[i] = n -i;
    }
    for(int i = 0; i < r; i++){
      cin >> p >> c;
      rotate(A.begin(),A.begin()+p-1,A.begin()+p+c-1);
      
    }
    cout << A[0]<< endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <complex>
using namespace std;

#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, a, b) for (int i = (a); i <= (b); i++)
#define repi(i, n) REPI(i, 0, n)
#define ALL(vs) (vs).begin(), (vs).end()
typedef long long ll;
typedef pair<int, int> pii;

#define MAX 52

void pop_front(vector<int> vs)
{
    reverse(ALL(vs));
    vs.pop_back();
    reverse(ALL(vs));
}

int main()
{
    int n, r;
    while (cin >> n >> r, n|r) {
        int arr[MAX];
        rep(i, n) arr[i] = i;
        reverse(arr, arr+n);

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

            int buf[MAX];
            rep(i, p-1) buf[i] = arr[i];
            rep(i, c)   arr[i] = arr[p-1+i];
            rep(i, p-1) arr[c+i] = buf[i];
        }

        printf("%d\n", arr[0]+1);
    }
    return 0;
}

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

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

C++: #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
  int n, r, p, c;
  int card[51], tmp1[51], tmp2[51];
  
  while(cin >> n >> r){
    if(n == 0 && r == 0) break;
    for(int i = 0 ; i < n ; i++){
      card[i] = n-i;
    }
    
    for(int i = 0 ; i < r ; i++){
      cin >> p >> c;
      p--;
      for(int j = 0 ; j < c ; j++) tmp1[j] = card[j+p];
      
      for(int j = p-1 ; j >= 0 ; j--) card[j+c] = card[j];
     
      for(int j = 0 ; j < c ; j++) card[j] = tmp1[j];
    
      /*cout << endl;
      for(int k = 0 ; k < n ; k++){
	cout << card[k] << endl;
	}*/
      
    }
    
    
    cout << card[0] << endl;
  }
  return 0;  
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;

int main() {
	int n, r;

	while(cin >> n >> r, n) {
		vi yama(n);
		REP(i, n) {
			yama[i] = n-i;
		}

		int p, c;
		REP(i, r) {
			cin >> p >> c;
			
			vi yama1(p-1);
			REP(j, p-1) {
				yama1[j] = yama[j];
			}

			vi yama2(c);
			REP(j, c) {
				yama2[j] = yama[j+p-1];
			}

			vi yama3(0);
			REP(j, yama2.size()) {
				yama3.push_back(yama2[j]);
			}

			REP(j, yama1.size()) {
				yama3.push_back(yama1[j]);
			}

			REP(j, yama3.size()) {
				yama[j] = yama3[j];
			}
		}

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



}