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>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

vector<ll> ans;

int main() {
	while (1) {
		ll n, r, p, c, card[51] = {};
		cin >> n >> r;
		if (n == 0 && r == 0)break;
		for (int i = 1; i <= n; i++)card[i] = n - i + 1;
		for (int i = 1; i <= r; i++) {
			cin >> p >> c;
			ll box[51] = {};
			for (int j = 1; j < p; j++)box[j] = card[j];
			for (int j = 1; j <= c; j++)card[j] = card[j + p - 1];
			for (int j = 1; j < p; j++)card[c + j] = box[j];
		}
		ans.push_back(card[1]);
	}
	for (int i = 0; i < ans.size(); i++)cout << ans[i] << endl;
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;



int main() {
	cout << fixed << setprecision(18);
	long long int n,r,p,c,x[120][120]={},mymin=INF,mymax=-INF,sum=0;
	cin>>n>>r;
	while(n!=0){
		mymin=INF;mymax=-INF,sum=0;
		for(int i=1;i<=n;i++){
			x[0][i]=n-i+1;
		}
		for(int i=1;i<=r;i++){
			cin>>p>>c;
			for(int j=1;j<=c;j++){
				x[i][j]=x[i-1][j+p-1];
			}
			for(int j=c+1;j<=c+p-1;j++){
				x[i][j]=x[i-1][j-c];
			}
			for(int j=c+p;j<=n;j++){
				x[i][j]=x[i-1][j];
			}
		}
		cout<<x[r][1]<<endl;
		cin>>n>>r;
	}
}

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

using namespace std;

int main(){
	vector<int> cards;
	vector<int> ::iterator cardsIterator;
	vector<int> ::iterator shuffuleIterator;
	int n,r,p,c;

	while(cin >> n >> r, n && r){
		cards.clear(); //初期化
		// カードの山生成
		for (int i = 0; i < n; ++i){
			cards.push_back(i+1);
		}
		// シャッフル
		while(cin >> p >> c){
			cardsIterator = cards.end();
			cardsIterator -= p + (c - 1);
			while(c--){
				cards.push_back(*cardsIterator);
				cards.erase(cardsIterator);
			}
			if (r == 0){
				break;
			}
		}
		// 一番上のカード表示
		cout << cards.back() << endl;
	}
}

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

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

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

int card[1000], tmp[1000], n, r;
int main()
{
loop:
  cin >> n >> r;
  if(!n && !r)
    return 0;
  for(int i = n; i > 0; i--)
    card[n - i] = i;
  for(int i = 0; i < r; i++)
  {
    int c, p;
    cin >> p >> c;
    for(int j = 0; j < p - 1; j++)
      tmp[j] = card[j];
    for(int j = 0; j < c; j++)
      card[j] = card[j + p - 1];
    for(int j = 0; j < p - 1; j++)
      card[j + c] = tmp[j];
  }
  cout << card[0] << endl;
  goto loop;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
	int n,r;
	while(cin >> n >> r){
		if(n==0 && r==0) break;
		int card[51];
		bool flag[51];
		for(int i=0; i<n; i++){
			card[i] = n-i;
			flag[i]=false;
		}
		for(int j=0; j<r; j++){
			int p,c;
			cin >> p >> c;
			vector<int> change;
			for(int i=p-1; i<p-1+c; i++){
				change.push_back(card[i]);
				flag[card[i]]=true;
			}
			for(int i=0; i<p-1; i++){
				change.push_back(card[i]);
				flag[card[i]]=true;
			}
			for(int i=p-1+c; i<n; i++){
				change.push_back(card[i]);
			}
			int count=0;
			vector<int>::iterator it = change.begin();
			while(it!=change.end()){
				card[count] = *it;
				count++;
				it++;
			}
		}
		cout << card[0] << endl;
	}
	return 0;
}

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

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

using namespace std;
typedef long long ll;

int main() {
    int n,r;
    while(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> ret;
            REP(j,p-1,p-1+c) {
                ret.push_back(v[j]);
            }

            rep(j,p-1) {
                ret.push_back(v[j]);
            }

            REP(j,p-1+c,n) {
                ret.push_back(v[j]);
            }

            rep(j,n) v[j] = ret[j];
        }

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

C++: #include<iostream>

#define rep(i,n) for(int i=0; i<n; i++)

int main(){
	int yama[51];
	int n,r;
	int tmp[51];

	while(std::cin >> n >> r && (n || r)){
		int c,p;
		rep(i,n){
			yama[i] = n-i;
		}
		rep(i,r){
			std::cin >> p >> c;
			rep(j,c){
				tmp[j] = yama[p-1+j];
			}
			rep(k,p-1){
				yama[p-1+c-k] = yama[p-1-k];
			}
			rep(l,c){
				yama[l] = tmp[l];
			}
		}
		std::cout << yama[0] << std::endl;
	}

	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cctype>

#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

typedef pair<int ,int> P;

int main()
{
    int N,R;
    while(cin >> N >> R && N != 0 && R != 0)
    {
        int card[N];
        rep(i,N+1) { card[i] = N - i; };
        rep(i,R)
        {
            int p,c;
            cin >> p >> c;

            int tmp_card[N];
            rep(j,N) { tmp_card[j] = 0; }
            rep(j,c){ tmp_card[j] = card[p - 1 + j]; } 
            rep(j,p-1) { tmp_card[j + c] = card[j]; }
            rep(j,c + p-1) { card[j] = tmp_card[j]; }
        }
        cout << card[0] << endl;
    }
}

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

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

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

int main() {
	int n,r;
	int p,c;
	int a[50];
	int b[50];
	while(1)
	{
		cin>>n>>r;
		if(n==0||r==0)
		{
			break;
		}
		int i=1;
		for(i=0;i<n;i++)
		{
			a[i]=n-i;
			b[i]=0;
		}
		i=0;
		while(r!=i)
		{
			cin>>p>>c;
			int j;
			for(j=0;j<c;j++)
			{
				b[j]=a[j+(p-1)];
			}
			for(j=0;j<p-1;j++)
			{
				b[c+j]=a[j];
			}
			for(j=0;j<(p-1)+c;j++)
			{
				a[j]=b[j];
			}
			i++;
		}
		cout<<a[0]<<endl;
	}
	return 0;
}