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>
using namespace std;

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

    int p, c;
    vector<int> hanafuda(n);
    for(int i = 0; i < n; i++){ hanafuda[i] = n - i; }
    for(int i = 0; i < r; i++){
      cin >> p >> c;
      --p;
      vector<int> tmp;
      for(int j = p; j < p + c; j++){ tmp.push_back(hanafuda[j]); }
      for(int j = p - 1; j >= 0; j--){ hanafuda[j + c] = hanafuda[j]; }
      for(int j = c - 1; j >= 0; j--){ hanafuda[j] = tmp[j];}
    }
    cout << hanafuda[0] << endl;
  }
  return 0;
}

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

int main() {
	int n, r;

	while (cin >> n >> r && n != 0 && r != 0) {
		int card[51];
		for (int i = 1; i <= n; i++) {
			card[i] = n - i + 1;
		}

		int p, c;
		for (int i = 0; i < r; i++) {
			cin >> p >> c;

			int temp[50];
			for (int j = 0; j < c; j++) {
				temp[j] = card[p + j];
			}
			for (int j = 1; j < p; j++) {
				card[p + c - j] = card[p - j];
			}
			for (int j = 0; j < c; j++) {
				card[j + 1] = temp[j];
			}
		}
		cout << card[1] << '\n';
	}

	return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>
 
#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
 
const int INF = 10000000;
using namespace std;
typedef long long  ll;
 
/** Problem1129 : Hanafuda Shuffle **/
int main()
{
    vector<int> card;
    int n, r, p, c;
     
    while (cin >> n >> r, n||r) {
        card.clear();
        rep(i, n)
            card.push_back(n-i);
         
        rep(k, r) {
            cin >> p >> c;
            vector<int> tmp;
            rep(i, c)
                tmp.push_back(card[i+p-1]);
            rep(i, p-1)
                tmp.push_back(card[i]);
            REP(i, p+c-1, n) {
                tmp.push_back(card[i]);
            }
            card = tmp;
        }
        cout << card[0] << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int deck[60];
int tmpdeck[60];

int main(){ _;
  int n,r,p,c;
  while(cin>>n>>r,!(n==0&&r==0)){
    REP(i,n) deck[i]=n-i;
    REP(i,r){
      cin>>p>>c;
      p--;
      copy(deck+p,deck+p+c,tmpdeck);
      copy(deck,deck+p,tmpdeck+c);
      copy(tmpdeck,tmpdeck+p+c,deck);
    }
    cout<<deck[0]<<endl;
  }
}

C++: #include <iostream>
#include <list>
#include <cstdlib>

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	int n,r;

	cin >> n;
	cin >> r;

	while (n != 0 || r != 0) {
		std::list<int> lst;
		int now = 1;

		for (int i = 0; i < n; i++) {
			lst.push_back(i+1);
		}

		for (int i = 0; i < r; i++) {
			int index = 1;
			int p,c;
			cin >> p;
			cin >> c;

			for (std::list<int>::iterator itr = lst.begin(); itr != lst.end();) {
				if (index >  n-(p-1)-c && index < n-(p-2) && r != n){
					lst.push_back(*itr);
					itr = lst.erase(itr);
				}else{
					itr++;
				}	
				index++;
			}
		}
		for (std::list<int>::iterator itr = lst.begin(); itr != lst.end(); ++itr) {
			if (now == n) {
				cout << *itr << "\n";
			}
			now++;
		}
		cin >> n;
		cin >> r;
	}	
	return 0;
}

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

int main() {
  while(true) {
    int ncard, r;
    cin >> ncard >> r;
    if(ncard == 0 && r == 0) break;
    vector<int> cards(ncard);
    for(int i = 0; i < ncard; ++i) cards[i] = ncard - i;
    for(int i = 0; i < r; ++i) {
      int p, c;
      vector<int> results;
      cin >> p >> c;
      for(int j = p - 1; j < p - 1 + c; ++j) {
        results.push_back(cards[j]);
      }
      for(int j = 0; j < p - 1; ++j) {
        results.push_back(cards[j]);
      }
      for(int j = p - 1 + c; j < ncard; ++j) {
        results.push_back(cards[j]);
      }
      cards = results;
    }
    cout << cards[0] << endl;
  }
  return 0;
}

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