Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		n, _ := strconv.Atoi(chunks[0])
		r, _ := strconv.Atoi(chunks[1])
		cards := make([]int, n, n)
		for i := 0; i < n; i++ {
			cards[i] = n - i
		}
		for i := 0; i < r; i++ {
			sc.Scan()
			chunks := strings.Split(sc.Text(), " ")
			p, _ := strconv.Atoi(chunks[0])
			c, _ := strconv.Atoi(chunks[1])
			block := make([]int, c, c)
			for j := 0; j < c; j++ {
				block[j] = cards[p+j-1]
			}
			for j := p - 2; j >= 0; j-- {
				cards[j+c] = cards[j]
			}
			for j := 0; j < c; j++ {
				cards[j] = block[j]
			}
		}
		fmt.Println(cards[0])
	}
}

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

using namespace std;

void printv(vector<int> v){
	for (int i = 0; i < v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

vector<int> subvec(vector<int> vec,int a,int b){
	vector<int> ret(b);
	for (int i = 0; i < b; i++){
		ret[i] = vec[i+a];
	}
	return ret;
}


int main(){
	while(1){
		int n; cin >> n;
		int r; cin >> r;
		if (n == 0 and r == 0) break;
		vector<int> str(n);

		for (int i = n; i > 0; i--){
				str[n-i] = i;
		}
		for (int i = 0; i < r; i++){
			vector<int> tmp;
			int p,c; cin >> p >> c;
			vector<int> str1 = subvec(str,0,p-1);
			vector<int> str2 = subvec(str,p-1,c);
			vector<int> str3 = subvec(str,p+c-1,str.size()-p-c+1);

			copy(str2.begin(),str2.end(),back_inserter(tmp));
			copy(str1.begin(),str1.end(),back_inserter(tmp));
			copy(str3.begin(),str3.end(),back_inserter(tmp));
			str = tmp;
		}
		cout << str[0] << endl;
	}		
	return 0;
}

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

int main()
{
    int before[60],after[60];
    int n,r;
    while(cin >> n >> r)
    {
        if(n==0 && r==0)break;
        for(int i=0;i<n+1;i++)
        {
            before[n-i]=i+1;
            after[n-i]=i+1;
        }
        
        int p,c,temp;
        for(int i=0;i<r;i++)
        {
            cin>>p>>c;
            for(int j=0;j<c;j++)
            {
                after[j+1]=before[p+j];
            }
            for(int j=0;j<p-1;j++)
            {
                after[c+j+1]=before[j+1];
            }
            for(int j=0;j<55;j++)
            {
                before[j]=after[j];
            }
        }
        cout << after[1]<< endl;
    }

    return 0;
}

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

int n,r;
int s,t;
int deck1[50],deck2[50];

void shuffle(int p,int c);

int main()
{
        while(cin >> n >> r){
                if(n==0 && r==0) break;
                for(int i=0;i<n;i++){
                        deck1[i] = n-i;
                }

                for(int i=0;i<r;i++){
                        cin >> s >> t;
                        shuffle(s,t);
                }

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

        return 0;
}

void shuffle(int p,int c)
{
        for(int i=0;i<c;i++) deck2[i] = deck1[p-1+i];
        for(int i=0;i<p-1;i++) deck2[c+i] = deck1[i];
        for(int i=0;i<c+p-1;i++) deck1[i] = deck2[i];
}

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

int main(void)
{
	while(1)
	{
		int num, action;
		cin>>num>>action;
		if(num == 0 && action == 0)
			break;

		vector<int> cards(num);
		for(int i= 0; i < num; i++)
			cards[i]= num-i;

		for(int i= 0; i < action; i++)
		{
			int startc, numc;
			cin>>startc>>numc;
			vector<int> res(num);

			for(int j= 0; j < numc; j++)
				res[j]= cards[startc-1+j];
			for(int j= 0; j < startc-1; j++)
				res[numc+j]= cards[j];
			for(int j= startc+numc-1; j < num; j++)
				res[j]= cards[j];
			for(int j= 0; j < num; j++)
				cards[j]= res[j];
		}
		cout<<cards[0]<<endl;
	}
}

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

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

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;
}