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>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,R;
  cin >> N >> R;
  while(N != 0){
    string S = "";
    for(int i=N; i>=1; i--){
      S += i + '0';
    }
    for(int i=0; i<R; i++){
      int p,c;
      cin >> p >> c;
      p--;
      S = S.substr(p,c) + S.substr(0,p) + S.substr(p+c);
    }
    cout << S[0]-'0' << endl;
    cin >> N >> R;
  }
  return 0;
}

C++: #include<stdio.h>

int main() {

	int n, r;
	int array[51];
	int tmp[51];
	while (1) {
		scanf("%d %d", &n, &r);
		if (n == 0 && r == 0) break;

		for (int i = 1; i <= n; i++) {
			array[i] = i;
		}
		for (int i = 0; i < r; i++) {
			int p, c;
			scanf("%d %d", &p, &c);
			for (int j = 0; j < c; j++) {
				tmp[j] = array[n - (p - 1) - j];
			}
			for (int j = 0; j < (p - 1); j++) {
				array[n - (p - 1) - c + 1 + j] = array[n - (p - 1) + 1 + j];
			}
			for (int j = 0; j < c; j++) {
				array[n - c + 1 + j] = tmp[c - 1 - j];
			}
		}
		printf("%d", array[n]);
	}
}

C++: #include <iostream>
using namespace std;
int n,r;
int card[50];

void shuffle(int p,int c) {
  int temp[50];
  for(int i=0;i<n;i++) {
    temp[i] = card[i];
  }
  for(int i=0;i<c;i++) {
    card[i] = temp[p-1+i];
  }
  for(int i=c;i<c+p-1;i++) {
    card[i] = temp[i-c];
  }
}

int main() {
  int p,c;
  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;
      shuffle(p,c);
    }
    cout << card[0] << endl;
  }
}

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

using namespace std;

int n[1000]={},r[1000]={};
int p[1000][50] = {};
int c[1000][50] = {};
int i=0;

int d[50]={};
int e[50] = {}; //今の状態
int e2[50] = {};

int main(){
    while(1){
        scanf("%d %d",&n[i],&r[i]);
        if(n[i]== 0 && r[i]== 0){
            break;
        }
        for(int j=0;j<r[i];j++){
            scanf("%d %d",&p[i][j],&c[i][j]);
        }
        i++;
    }
    int times = i;
    for(i=0;i<times;i++){
        //初期化
        int s=0;
        for(int k = n[i]; k>0;k--){
            e[s] = k;
            s++;
        }
        for(int j=0;j<r[i];j++){
            s=0;
            for(int t=p[i][j]-1;t<p[i][j]+c[i][j]-1;t++){
                d[s] = e[t];
                s++;
            }
            for(int t = 0;t < n[i];t++){
                e2[t] = e[t];
            }
            for(int t = 0;t<c[i][j];t++){
                e[t] = d[t];
            }
            for(int t=0;t<n[i]-c[i][j];t++){
                e[t+c[i][j]] = e2[t];
            }

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

    return 0;
}

C++: #include <iostream>
#include <string>
#include <array>
#include <vector>
#include <math.h>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <queue>

#define MAX 100005
#define ll long long int
using namespace std;

int main(void) 
{
	int n, r;
	int i, j;
	vector <int> ans, p, c;
	int temp1, temp2;

	vector <int> huda(55);

	queue <int> temp; //????????????????´???????

	while (1) {
		cin >> n >> r;
		if (n == 0 && r == 0) {
			break;
		}

		for (i = 0; i < r; i++) {
			cin >> temp1 >> temp2;
			p.push_back(temp1);
			c.push_back(temp2);
		}

		huda[0] = 0;

		for (i = n; i > 0; i--) { //?????????????¨????
			huda[n - i + 1] = i;


		}

		for (i = 0; i < r; i++) {

			for (j = 0; j < c[i]; j++) {
				temp.push(huda[p[i] + j]); 
			}

			for (j = p[i] + c[i] - 1; j > c[i]; j--) {
				huda[j] = huda[j - c[i]]; // ??±???????????¨???
			}

			for (j = 1; j <= c[i]; j++) {
				huda[j] = temp.front();
				temp.pop();

			}



		}

		ans.push_back(huda[1]);

		p.clear();
		c.clear();

		


	}



	 
	for (i = 0; i < ans.size(); i++) {
		cout << ans[i] << endl;
	}


	return (0);
}

C++: #include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;




int main(int argc, const char * argv[])
{
    int n, r;
    while(cin >> n >> r){
        if(n == 0 || r == 0) return 0;
        
        int cards[n];
        int next[n];
        
        for(int i = 0; i < n; i++){
            cards[i] = n - i;
        }
        
        // 　DEBUG
        /*
        for(int i = 0; i < n; i++){
            cout << cards[i] << " ";
        }
        cout << "\n";
        */
        
        int p, c;
        for(int i = 0; i < r; i++){
            cin >> p >> c;
            int j = 0;
            for(j = 0; j < c; j++){
                next[j] = cards[p+j-1];
            }
            for(int k = 0; k < p-1; k++){
                next[j] = cards[k];
                j++;
            }
            for(;j < n; j++){
                next[j] = cards[j];
            }
            
            for(int j = 0; j < n; j++){
                cards[j] = next[j];
            }
            /*
            for(int i = 0; i < n; i++){
                cout << cards[i] << " ";
            }
            cout << "\n";
             */
        }
        
        cout << cards[0] << "\n";
    }
    return 0;
}

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

using namespace std;

int main(){
	while(true){
		int n,r;
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		int cards[2][n];
		for (int i=0;i<n;++i){
			cards[0][i] = n-i;
			cards[1][i] = n-i;
		}
		for (int i=0;i<r;++i){
			int f = i%2;
			int t = (i+1)%2;
			int p,c;
			cin >> p >> c;
			for (int l=0;l<p-1;++l){
				cards[t][l+c] = cards[f][l];
			}
			for (int l=p-1;l<p+c-1;++l){
				cards[t][l-(p-1)] = cards[f][l];
			}
		}
		int t = r%2;
		cout << cards[t][0] << endl;
	}
	return 0;
}