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 <stdio.h>
#include <stdlib.h>

void shuffle(int *card,int p,int c);

int main(void){
	int i,j,n,r,p,c;
	int *card;
	
	while(1){
		x = scanf("%d %d",&n,&r);
		if((n == 0) && (r == 0)){
			break;
		}
		card = (int *)calloc(n,sizeof(int));
		if(card == NULL){
			printf("メモリが確保できません\n");
			return -1;
		}
		for(i = 0;i < n; i++){
			card[i] = n - i;
		}
		for(i = 0;i < r; i++){
			scanf("%d %d",&p,&c);
			shuffle(card,p,c);
		}

		printf("%d\n",card[0]);
		free(card);
	}
	return 0;
}

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

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

using namespace std;

int main(){
    int n,r;
    while(scanf("%d%d",&n,&r),n!=0){
        int card[51];
        for(int i=0;i<51;i++){
            card[i] = n-i;
        }

        while(r--){
            int p,c;
            cin >> p >> c;
            int tmp[51];
            for(int i=0;i<p-1;i++){
                tmp[i] = card[i];
            }
            for(int i=0;i<c;i++){
                card[i] = card[p-1+i];
            }
            for(int i=c;i<c+p-1;i++){
                card[i] = tmp[i-(c)];
            }
        }

        cout << card[0] << 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++) {
		cin >> input[pos][0] >> input[pos][1];
	}																//ここまで入力
	int whtop = 1;													//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) {
				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 <string>

using namespace std;

int main(void){
	int p,c;

	for(int n,r;cin >> n >> r,n||r;){
		string card;

		for(int i=0;i<n;i++)
			card+=(n-i+0x30);

		for(int i=0;i<r;i++){
			cin >> p >> c;
			if(p!=1)
				card = card.substr(p-1,c)+card.substr(0,p-1)+card.substr(p+c-2);
		}

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

	return 0;
}

C++: #include <iostream>
#include <vector>
 
using namespace std;
 
typedef vector<int> VI;
 
int main ( void )
{
int n, r;
while ( cin >> n >> r, n | r ) {
VI cards( n );
for ( int i = 0; i < n; ++i ) {
cards[i] = n - i;
}
for ( int i = 0; i < r; ++i ) {
VI t( cards );
int p, c;
cin >> p >> c;
for ( int j = 0; j + 1 < p; ++j ) { // pの束を移動
t[c + j] = cards[j];
}
for ( int j = 0; j < c; ++j ) { // cの束を移動
t[j] = cards[p - 1 + j];
}
cards = t;
}
cout << cards[0] << endl;
}
return 0;
}

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

void shuffle( vector <int>& cards, int p, int c )
{
    vector <int> replaced( cards.begin() + p - 1, cards.begin() + p + c - 1 );
    replaced.insert( replaced.end(), cards.begin(), cards.begin() + p - 1 );
    for ( int i = 0; i < p+c-1; i++ ) cards[i] = replaced[i];
}

int main( void )
{
    int n, r, p, c;

    while ( cin >> n >> r && n > 0 && r > 0 )
    {
        vector <int> cards( n );
        for ( int i = 0; i < n; i++ ) cards[i] = n - i;
        for ( int i = 0; i < r; i++ )
        {
            cin >> p >> c;
            shuffle( cards, p, c );
        }
        int answer = cards[0];
        cout << answer << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long int
#define MOD 1000000007
#define pb push_back
#define ub upper_bound
#define lb lower_bound

using namespace std;

int main(){
    int n,r;
    int c[50];
    int cp[50];
    int com1,com2;
    int cnt=0;
    while(1){
        cin >> n >> r;
        for(int i=0;i<50;i++){
            c[i]=n-i;
        }
        if(n==0||r==0){
            break;
        }
        
        for(int i=0;i<r;i++){
            for(int i=0;i<50;i++){
                cp[i]=0;
            }
            cin >> com1 >> com2;
            cnt=0;
            for(int i=com1-1;i<com1-1+com2;i++){
                cp[cnt]=c[i];
                cnt++;
            }
            for(int i=com1-2;i>-1;i--){
                c[i+com2]=c[i];
            }
            for(int i=0;i<com2;i++){
                c[i]=cp[i];
            }
        }
        cout << c[0] << endl;
    }
    return 0;
}

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

typedef long long LL;
#define rep(i ,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define all(v) (v).begin(),(v).end()
#define arycpy(ary1,ary2,N) memcpy(ary2,ary1,sizeof(int)*N) //ary1:???????????? ary2:????????????
typedef vector<int> vi;


int main(){
	while (1){
		int n, r;
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		int *num = new int[n];
		for (int i = 0; i < n; i++){
			num[i] = n-i;
		}
		for (int i = 0; i < r; i++){
			int p, c; cin >> p >> c;
			int *ary = new int[n];
			rep(j, n) ary[j] = 0;

			//????????\????????????(c???)?????£??\
			for (int j = 0; j < c; j++){
				ary[j] = num[p - 1 + j];
			}
			
			//??????????????????????????????(p-1???)?????£??\
			for (int j = c; j <c+p-1; j++){
				ary[j] = num[j - c];
			} 

			//rep(j, n) cout << ary[j] << " ";
			//cout << endl;

			for (int j = p+c-1; j < n; j++){
				ary[j] = num[j];
			}
			arycpy(ary, num, n);
			//rep(j, n) cout << num[j] << " ";
			//cout << endl;
		}
		cout << num[0] << endl;
	}
	return 0;
}

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

int main(void)
{
	int n, r;
	while (cin >> n >> r, n && r){
		vector <int> card, tmp;
		// いちばんさいしょ＝いちばんうえ
		for (int i = n; 0 < i; i--){
			card.push_back(i);
		}
		/*
		for (int i = 0; i < n; i++){
			cout << card[i] << " ";
		}
		puts("");
		*/
		int p, c;
		while (r--){
			cin >> p >> c;
			for (int i = p; i < p+c; i++){
				tmp.push_back(card[i-1]);
			}
			for (int i = 0; i < p-1; i++){
				tmp.push_back(card[i]);
			}
			for (int i = p+c-1; i < n; i++){
				tmp.push_back(card[i]);
			}
			card = tmp;
			/*
			for (int i = 0; i < n; i++){
				cout << card[i] << " ";
			}
			puts("");
			*/
			tmp.clear();
		}
		cout << card[0] << endl;
	}

	return 0;
}