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 <deque>
#include <vector>

using namespace std;

int main( void ){
	vector< int > result;
	deque< int > card;
	while( true ){
		int n, r;
		cin >> n >> r;
		if( n == 0 && r == 0 )
			break;
		for( int i = 1; i < n + 1; i++ ){
			card.push_front( i );
		}
		for( int i = 0; i < r; i++ ){
			int p, c;
			cin >> p >> c;
			for( auto itr = card.begin(); itr != card.end(); ++itr ){
				if( ( *itr ) =< p ){
					int temp = ( *itr );
					card.erase( itr );
					card.push_front( temp );
				}
			}
		}

		result.push_back( card.front() );
			
	}

	for( auto itr = result.begin(); itr != result.end(); ++itr ){
		cout << ( *itr ) << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int cards[50];
int n, r;

void cut(int p, int c) {
	vector<int> temp(c);
	for (int i = 0; i < c; i++) {
		temp[i] = cards[p + i - 1];
	}

	for (int i = p - 2; i >= 0; i--) {
		cards[i + c] = cards[i];
	}

	for (int i = 0; i < c; i++) {
		cards[i] = temp[i];
	}
}

int main() {
	while (true) {
		cin >> n >> r;
		if (!n && !r) break;

		for (int i = 0; i < n; i++) {
			cards[i] = n - i;
		}

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

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

	return 0;
}

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

int main(void)
{

	int n,r;
	int p,c;
	int i1,i2;

	while(1){

		cin >> n >> r;
		if (n==0 && r==0) break;

		vector<int> fuda(n),temp(n);

		/* syokika */
		for(i1=0;i1<n;i1++){
			fuda[i1] = n-i1;
	//		cout << fuda[i1] << " ";

		}


		for(i2=0;i2<r;i2++){
			
			cin >> p >> c;

			

			/* copy */
			for(i1=0;i1<p-1;i1++){
				temp[i1] = fuda[i1];
			}


			/* shuffle */
			for(i1=0;i1<c;i1++){
				fuda[i1] = fuda[p-1+i1];
			}
			for(i1=c;i1<p-1+c;i1++){
				fuda[i1] = temp[i1-c];
			}


	/*		for(i1=0;i1<n;i1++){
				cout << fuda[i1] << " ";
			}*/


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

	return 0;
}

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

int main(){
  int n,r;
  while(cin>>n>>r && n>0 && r>0){
    vector<int> v;
    for(int i=n;i>0;i--)v.push_back(i);
    while(r--){
      int p,c;
      cin>>p>>c;
      vector<int>::iterator it = v.begin();
      rotate(it,it+p-1,it+p+c-1);
    }
    cout<<v[0]<<endl;
  }
  return 0;
}

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

int main() {

    while(true){

        int n,r;
        cin >> n >> r;

        if(n == 0){
            break;
        }

        int a[n];
        for(int i=0; i<n; i++){
            a[i] = n-i;
        }

        for(int loop=0; loop<r; loop++){

            int p,c;

            cin >> p >> c;

            int tmp[n];

            for(int i=0; i<n; i++){
                tmp[i] = a[i];
            }

            int count = 0;

            for(int i=0; i<c; i++){
                a[count] = tmp[i+p-1];
                count++;
            }
            for(int i=0; i<p-1; i++){
                a[count] = tmp[i];
                count++;
            }

        }

        cout << a[0] << endl;

    }

    return 0;
}

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

int main(){
    int n,r,p,c;
    while(cin >> n >> r, n&&r){
        vector<int> cards;
        for(int i = 0; i < n; i++){
            cards[i] = n - i;
        }
        while(r--){
            cin >> p >> c;
            vector<int> cpCards = cards;
            int pos = 0;
            for(int i = p - 1; i < p - 1 + c; i++){
                cards[pos] = cpCards[i];
                pos++;
            }
            for(int i = 0; i < p - 1; i++){
                cards[pos] = cpCards[i];
                pos++;
            }
        }
        cout << cards.front() << endl;
    } 
}

C++: #include <cstdio>

int n, r;
int card[50], tmp[50];

int main(){
	while(scanf("%d%d", &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++){
			int p,c; scanf("%d%d", &p, &c); p--;
			for(int i = p; i < p+c; i++) tmp[i-p] = card[i];
			for(int i = p-1; i >= 0; i--) card[i+c] = card[i];
			for(int i = 0; i < c; i++) card[i] = tmp[i];
			for(int i = 0; i < n; i++) printf("%d ", card[i]);
			printf("\n");
		}
		printf("%d\n", card[0]);
	}
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<random>
#include<map>
#include<queue>
using namespace std;

int main(){

  int n, r;
  while(cin >> n >> r){
    if( n == 0 && r == 0 ) break;
    vector<int> p(r);
    vector<int> c(r);
    for(int i=0; i<r; i++) cin >> p[i] >> c[i];

    vector<int> d(n);
    for(int i=0; i<n; i++) d[i] = n-i;

    for(int i=0; i<r; i++){
      vector<int> tmp;
      for(int j=0; j<c[i]; j++){
        tmp.push_back( d[ p[i]-1+j ] );
        d[ p[i]-1+j ] = -1;
      }
      for(int j=0; j<n; j++){
        if( d[j] == -1 ) continue;
        tmp.push_back( d[j] );
      }
      d = tmp;
      // for(int j=0; j<n; j++) cerr << d[j] << " ";
      // cerr << endl;
    }
    cout << d[0] << endl;
  }

  return 0;
}

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

#define R input[0][1]

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++) {					//r回のシャッフルの仕方を入力
		cin >> input[pos][0] >> input[pos][1];
	}																//ここまで入力

	/*シャッフルもどし*/
	int whtop = 1;													//最後一番上にいるカードは、今何番目にいる？
	if (R==0)return input[0][0];									//一回もシャッフルしないならコレ

	whtop = input[input[0][1]][0];									//一回目のもどしだけ別枠
	R--;
	while (input[0][1] != 0) {	
		if (whtop <= input[R][1]) whtop = whtop + input[R][0] - 1;
		else if ((input[R][0] + input[R][1] - 1) < whtop) whtop = whtop;
		else whtop = whtop - input[R][1];
		R--;
	}
	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>
using namespace std;
int main(){

  int n, r, p, c, y;
  int x = 0;

  while(1){
    cin >> n >> r;
    if(n==0 || r==0)break;
      for(int i=0; i<r; i++){
        cin >> p >> c;
        if(p >= c){
          y = p - c;
          x += y;
        }
          if(x > 10){
            x -= 10;
          }
      }
      cout << x << endl;
      x = 0;
      y = 0;
  }
  return 0;
}