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)
{

	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>

using namespace std;
int main(){
	int zero;
	while(1){
		int card,cut;
		
		cin >> card >> cut;
		if(card == 0 && cut == 0){
			return 0;
		}
		
		int topcard = card;
		
		int *c = new int[cut];
		int *p = new int[cut];

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

		for(int i=cut-1; i>=0; --i){
			if(topcard > card-c[i]){
				topcard -= (p[i]-1);
			}
			else if( topcard > card-c[i]-(p[i]-1) ){
				topcard += c[i];
			}
		}
		cout << topcard << endl;
		
		delete[] c;
		delete[] p;
		
	}


}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int n, r;
    cin >> n >> r;
    if (n == 0 && r == 0){
      break;
    }
    vector<int> ans(n);
    for (int i = 0; i < n; i++){
      ans[i] = n - i;
    }
    for (int i = 0; i < r; i++){
      int p, c;
      cin >> p >> c;
      p--;
      vector<int> ans2 = ans;
      for (int j = 0; j < c; j++){
        ans2[j] = ans[j + p];
      }
      for (int j = c; j < c + p; j++){
        ans2[j] = ans[j - c];
      }
      swap(ans, ans2);
    }
    cout << ans[0] << endl;
  }
}

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

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n,r;
    while(cin >> n >> r && n){
        string s(n,0);
        rep(i,n) s[n-i-1] = i+1;
        rep(i,r){
            int p,c;
            cin >> p >> c;
            s = s.substr(p-1,c) + s.substr(0,p-1) + s.substr(p-1+c);
        }
        cout << (int)s[0] << endl;
    }
}

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, r--){
			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 "bits/stdc++.h"
using namespace std;

int main() {
	int n,r;
	while (cin >> n>>r) {
		if (!n)break;
		int a[50];
		int b[50];
		for (int i = 0; i < n; ++i)a[i] = n - i;
		for (int i = 0; i < r; ++i) {
			int s, e, j = 0;
			cin >> s>> e;
			for (; j < e; j++) b[j] = a[s + j - 1];
			for (; j < s + e - 1; j++)b[j] = a[j - e];
			for (; j < n; ++j)b[j] = a[j];
			for (j = 0; j < n; ++j)a[j] = b[j];
		}
		cout << a[0] << endl;
		
	}
	return 0;
}

C++: #include<cstdio>
void shuffle (int [], int, int);

int main(){
  int n,r,p,c;
  while(1){
    scanf("%d%d",&n,&r);
    if(n==0 && r==0)
      break;
    int data[n];
    for(int i=0;i<n;i++)
      data[i]=n-i;
    for(int i=0;i<r;i++){
      scanf("%d%d",&p,&c);
      shuffle(data,p,c);
    }
    printf("%d\n",data[0]);
  }
  return 0;
  
}

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

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
const int INF = 1e9;
const int MOD = 1000000007;

int main(){
    while(1){
        int n,r;
        cin >> n >> r;
        if(n==0 && r==0) break;
        vector<int> a(n);
        iota(a.rbegin(),a.rend(),1);
        rep(i,r){
            int p,c;
            cin >> p >> c;
            rotate(a.begin(),a.begin()+p-1,a.begin()+p-1+c);
        }
        cout << a[0] << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#define N 50
using namespace std;

int main(){

  int n,r,ans;
  int operate[N][2];

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

      for(int i=0;i<r;i++)cin >> operate[i][0] >> operate[i][1];
      ans = n;

     
      for(int i=r-1;i>=0;i--){
	if(n-operate[i][1] <= ans && ans <= n)
	  {
	    if(n == operate[i][1])continue;
	    ans = ans-operate[i][0]+1;
	   
	    continue;
	  }
	else{
	  ans += operate[i][1];


	}
      }

      cout << ans << endl;



    }

}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
	int card[50][50]={0};
	int mem[50]={0};
	int n;
	int r;
	int k = 0 ;
	int p,c;
	while(1){
		cin >>n >>r;
		if ((n==0)&&(r==0)) break;
		for(int i =0;i<n;i++){
			card[k][i]=i;
		}	
		for (int j=0;j<r;j++){
			cin >> p >> c ;
			for(int l=0;l<n;l++){
				mem[l]=card[k][l];
			}
			for(int m=0;m<p-1;m++){
				card[k][n-p-c+1+m]=mem[n-p+1+m];
			}
			for(int l=0;l<c;l++){
				card[k][n-c+l]=mem[n-p-c+1+l];
			}
		}
		cout << card[k][n-1] <<endl;
		k++;

	}
	
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)

int card[51];
int ncard[51];
int n, r, c, p;

int main()
{
    while(cin >> n >> r && n)
    {
        REP(n) card[i] = n - i;

        REP(r)
        {
            cin >> p >> c;

            rep(j,n) ncard[j] = card[j];
            //rep(j,n)cout <<j<< ":" << card[j] << endl;
            
            rep(j,p - 1) ncard[c + j] = card[j];
            rep(j, c) ncard[j] = card[j + p - 1];
            
            rep(j,n) card[j] = ncard[j];
        }
       // REP(n)cout <<i << ":" << card[i] << endl;

        cout << card[0] << endl;

    }
    
    return 0;
}