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

C++: #include<stdio.h>

int main(void){
  int n;
  int r;
  int p;
  int c;
  int i;
  int j;
  for(;;){
    scanf("%d %d",&n,&r);
    if(n==0)
      {
	if(r==0){break;}
      }
    int card[n];
    for(i=n;i>0;i--)
      {
	card[n-i]=i;
      }
    /*--------------確認用-------------------
    printf("card:");
    for(i=0;i<n;i++)
      {
	printf("%d ",card[i]);
      }
    printf("\n");
    /*--------------------------------------*/
    for(i=0;i<r;i++)
      {
	scanf("%d %d",&p,&c);
	int card_p[p-1];
	int card_c[c];
	for(j=0;j<p-1;j++)
	  {
	    card_p[j]=card[j];
	  }
	/*---------確認用-------------------------
	printf("card_p:");
	for(j=0;j<p-1;j++)
	  {
	    printf("%d ",card_p[j]);
	  }
	printf("\n");
	/*----------------------------------------*/
	for(j=0;j<c;j++)
	  {
	    card_c[j]=card[p+j-1];
	  }
	/*---------確認用-------------------------
	printf("card_c:");
	for(j=0;j<c;j++)
	  {
	    printf("%d ",card_c[j]);
	  }
	printf("\n");
	/*----------------------------------------*/
	for(j=0;j<c;j++)
	  {
	    card[j]=card_c[j];
	  }
	for(j=0;j<p-1;j++)
	  {
	    card[c+j]=card_p[j];
	  }
	/*-----------------------------------------
	for(j=0;j<n;j++)
	  {
	    printf("%d ",card[j]);
	  }
	printf("\n");
	/*----------------------------------------*/
      }
    printf("%d\n",card[0]);
  }
  
  return 0;
}