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>

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()
{
	int output[1000];
	char topos = 0;
	while (1) {
		int check;
		check=input();
		if (check == 0)break;
		else {
			output[topos] = check;
			topos++;
		}
	}

	char sendpos = 0;
	while (sendpos < topos) {
		cout << output[sendpos] << endl;
		sendpos++;
	}


}

C++: #include <iostream>
#include <math.h>
#include <array>
#include <algorithm>
using namespace std;
int n, r, p, c;

int main(){
  while( cin >> n >> r && n > 0){
    int a[50];
    for(int i = 1; i < n+1; i++){
      a[i-1] = i;
    }
    for (int i = 0; i < r; i++){
      cin >> p >> c;
      rotate(a+n+1-c-p, a+n+1-p, a+n);
    }


    cout << a[n-1] << endl;


  }




}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
using mat = vector<vector<ll>>;

inline void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[5001][5002];



signed main(){
	IOS();
	ll n, r;
	while(1){
		cin >> n >> r;
		if(n == 0 && r == 0)break;
		vector<ll> a(n + 1), a2(n + 1);
		for (int i = 0;i <= n;++i) {
			a[i] = a2[i] = n - i + 1;
		}
		for (int i = 0;i < r;++i) {
			a = a2;
			ll p, c;
			cin >> p >> c;
			for (int i = 0;i < c;++i) {
				a2[i + 1] = a[p + i];
			}
			for (int i = 1;i < p;++i) {
				a2[i + c] = a[i];
			}
		}
		cout << a2[1] << endl;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

int cards[51];

void cut_operation(int p, int c) {
  int tmp[51];
  int tmp2[51];
  for (int i = 0; i < p - 1; i++)  {
    tmp[i] = cards[i];
  }
  for (int i = 0; i < c; i++) {
    tmp2[i] = cards[p - 1 + i];
  }
  for (int i = 0; i < c; i++)  {
    cards[i] = tmp2[i];
  }
  for (int i = 0; i < p - 1; i++) {
    cards[i + c] = tmp[i];
  }
}

int main() {
  int n, r;
  while (true) {
    cin >> n >> r;
    if (n + r == 0) break;
    for (int i = 0; i < 51; i++) {
      cards[i] = n - i;
    }
    for (int i = 0; i < r; i++) {
      int p, c;
      cin >> p >> c;
      cut_operation(p, c);
    }
    cout << cards[0] << endl;
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(v) (v).begin(),(v).end()

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    while(1){
        int n;
        vector<int> vec;
        cin >> n;
        if(n == 0){
            break;
        }
        rep(i,n){
            vec.push_back(n-i);
        }
        int r;
        cin >> r;
        rep(i,r){
            int a,b;
            cin >> a >> b;
            vector<int> up;
            vector<int> bf;
            for(int i = a-1;i<a+b-1;i++){
                up.push_back(vec[i]);
            }
            rep(i,b){
                bf.push_back(up[i]);
            }
            rep(i,a){
                bf.push_back(vec[i]);
            }
            for(int i = a+b-1;i < n;i++){
                bf.push_back(vec[i]);
            }
            vec.clear();
            vec = bf;
        }
        cout << vec[0] << "\n";
    }
	return 0;
}

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

using namespace std;

int N, R, p, c;

int main()
{
	while (cin >> N >> R && N) {
		vector<int> A(N+1, 0);
		
		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>
using namespace std;
int main(){
	int n,r,p,c;
	int t[1000],a[1000],b[1000];
	while(cin>>n>>r,n||r){
		for(int i=0;i<n;i++)
		t[i]=n-i;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			for(int j=0;j<p-1;j++)
			a[j]=t[j];
			for(int j=0;j<c;j++)
			b[j]=t[j+p-1];
			for(int j=0;j<c;j++)
			t[j]=b[j];
			for(int j=0;j<p-1;j++)
			t[j+c]=a[j];
		}
		cout<<t[0]<<endl;
	}
	return 0;
}

C++: int main(){
  int n,k;
  while(1){
    cin >> n >> k;
    if(n==0&&k==0) break;
    vector<int> card(n+1,0);
    for(int i=1;i<n+1;++i) card[i]=n-i+1;

    //for(int i=1;i<n+1;++i){
      //cout << card[i] << endl;
    //}

    for(int i=0;i<k;++i){
      int p,c;
      cin >> p >> c;
      rotate(card.begin()+1,card.begin()+p,card.begin()+p+c);
      for(int j=1;j<n+1;++j){
	//cout << card[j] << endl;
      }
    }
    cout << card[1] << endl;
  }
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

using namespace std;

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;

int main(void) {
    while (true) {
        int n;
        int r;
        cin >> n >> r;
        if (n == 0) {
            break;
        }

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

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()
{
	int output[1000];
	char topos = 0;
	while (1) {
		int check;
		check=input();
		if (check == 0)break;
		else {
			output[topos] = check;
			topos++;
		}
	}

	char sendpos = 0;
	while (sendpos < topos) {
		cout << output[sendpos] << endl;
		sendpos++;
	}


}