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>

using namespace std;

int cut(int n, int r, int s[60]){
	int p, c;
	int temp[60] = {0};

	for(int i = 0;i < r;i++){
		cin >> p >> c;
		for(int j = 0;j <= n;j++){
			temp[j] = s[j];
		}
		for(int j = 0;j < p;j++){
			s[n - p - c + j + 2] = temp[n - p + j + 2];
		}
		for(int j = 0;j < c;j++){
			s[n - c + 1 + j] = temp[n - p - c + j + 2];
		}
	}

	return s[n];
}

int main(){
	int n, r, p, c, s[60];
	while(1){
		cin >> n >> r;
		if(n == 0 && r == 0) break;

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

		int ans = cut(n, r, s);

		cout << ans << endl;
	}

	return 0;
}

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

C++: #include <bits/stdc++.h>
using namespace std;

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

C++: #include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
	int n, r;
	vector<int> card;
	while(true){
		cin >> n >> r;
		if(!n && !r) break;
		card.clear();
		// 1 .. n
		for(int i = 1; i <=n ; i++){
			card.push_back(i);
		}

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

			cin >> p >> c;
			if(n == c) continue;
			
			vector<int>::iterator it = card.end() - p - c + 1;
			
			// temp
			for(int j = 0; j < c; j++){
				card.push_back(*it);
				it++;
			}
			//erase
			card.erase(it  - c, it);
			
			/*
			it = card.begin();
			while(it != card.end()){
				cout << " " << *it;
				it++;
			}
			cout << endl;
			*/
		}
		cout << card[n-1] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;
int n,r;
int p,c;
vector<int> card;
vector<int> tmp;
int main(){
  while(true){

    cin >> n >> r;
    if(n==0&&r==0)break;
    card.resize(n+2);
    REP(i,n)card[i]=i+1;
    REP(i,r){
      cin >> p >> c;
      for(int j=n-p+1;j<n;j++){
	tmp.push_back(card[j-c]);
	card[j-c] = card[j];
      }
      REP(k,n)cout << card[k] << " ";
	cout << "\n";
	if(p!=1)
	  for(int j=n-c;j<n;j++)
	    card[j] =tmp[j-n+c];
      REP(k,n)cout << card[k] << " ";
      cout << "\n";
      tmp.clear();
    }
    cout << card[n-1] << endl;
    card.clear();

  }

  return 0;
    
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>



using namespace std;



int main()
{
	int n, r, p, c;
	int yama[50], temp[50];
	
	while (cin >> n >> r)
	{
		if (n == 0 && r == 0) break;
		
		//山の初期化
		for (int i=0; i<n; i++)
		{
			yama[i] = n - i;
		}
		
		//カット操作
		for (int i=0; i<r; i++)
		{
			cin >> p >> c;
			for (int j=0; j<p-1; j++)
			{
				temp[c+j] = yama[j];
			}
			for (int j=p-1; j<p+c-1; j++)
			{
				temp[j-p+1] = yama[j];
			}
			for (int j=0; j<p+c-1; j++)
			{
				yama[j] = temp[j];
			}
		}
		
		/*
		//テスト出力
		for (int i=0; i<n; i++)
		{
			cout << yama[i] << endl;
		}
		*/
		
		cout << yama[0] << endl;
	}
	
	return 0;
}

C++: #include <stdio.h>

int main(void){

  char inputs[6], tmp[51];
  int inputs_shuffle[51][2], inputs_nr[2], stack[52];
  int loop1, loop2, loop3;

  inputs_nr[0] = '\0';
  inputs_nr[1] = '\0';

  for(loop1 = 0; loop1 < 51; loop1++){
    inputs_shuffle[loop1][0] = '\0';
    inputs_shuffle[loop1][1] = '\0';
  }

  while((inputs_nr[0] == '\0') || (inputs_nr[1] == '\0')){ // get <n r>
    printf("input 'n r'\n");
    scanf("%d %d", &loop1, &loop2);

    inputs_nr[0] = loop1;
    inputs_nr[1] = loop2;
    
    
    if((inputs_nr[0] < 1) || (inputs_nr[0] > 50)){
      printf("<n> must be more than 1 and less than 50.\n");
      inputs_nr[0] = '\0';      // 1 <= n <= 50
      inputs_nr[1] = '\0';
    }

    if((inputs_nr[1] < 1) || (inputs_nr[1] > 50)){
      printf("<r> must be more than 1 and less than 50.\n");
      inputs_nr[1] = '\0';      // 1 <= r <= 50
      inputs_nr[0] = '\0';
    }
  }



  
  for(loop1 = 0; loop1 < 50; loop1++){  // get <p c>

    printf("input 'p c'[%d]\n", loop1 + 1);
    scanf("%d %d", &loop2, &loop3);

    inputs_shuffle[loop1][0] = loop2;
    inputs_shuffle[loop1][1] = loop3;

    
    if((inputs_shuffle[loop1][0] + inputs_shuffle[loop1][1]) > (inputs_nr[0] + 1)){
      printf("(p + c) must be less than (%d + 1)\n", inputs_nr[0]);
      loop1--;   //  (p + c) must be less than (n + 1).
    }
    else if((inputs_shuffle[loop1][0] == 0) && (inputs_shuffle[loop1][1] == 0)){
      break;     //  if ((p == 0) && (c == 0)), escape this loop.
    }
  }

  for(loop1 = 0; loop1 < 52; loop1++){  // make the stack
    if(inputs_nr[0] != 0){
      stack[loop1] = inputs_nr[0];
      inputs_nr[0]--;
    }
    else       stack[loop1] = '\0';
  }
  // stack[0], stack[1], stack[2], .......
  //       n ,      n-1,      n-2, .......

  loop1 = 0;

  while(((inputs_shuffle[loop1][0] != 0) && (inputs_shuffle[loop1][1] != 0)) && loop1 != 51){

    for(loop2 = 0; loop2 < (inputs_shuffle[loop1][0] - 1); loop2++){ //
      tmp[loop2] = stack[loop2];
    }

    for(loop3 = 0; loop3 < inputs_shuffle[loop1][1]; loop3++, loop2++){
      stack[loop3] = stack[loop2];
    }

    for(loop2 = 0; loop2 < (inputs_shuffle[loop1][0] - 1); loop2++, loop3++){
      stack[loop3] = tmp[loop2];
    }

    for(loop2 = 0; loop2 < 52; loop2++){
      tmp[loop2] = '\0';
    }

    loop1++;
  }

  printf("%d\n", stack[0]);


  return 0;

}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m;
    while (true) {
        cin >> n >> m;
        if (!n && !m) break;
        int p, c;
        vector<int> a(n);
        vector<int> b;
        for (int i = 0; i < n; ++i) {
            a[i] = n-i;
        }
        for (int i = 0; i < m; ++i) {
            cin >> p >> c; --p; --c;
            for (int j = p; j < p+c+1; ++j) {
                b.push_back(a[j]);
            }
            for (int j = 0; j < p; ++j) {
                b.push_back(a[j]);
            }
            for (int j = p+c+1; j < n; ++j) {
                b.push_back(a[j]);
            }
            a = b;
            b.clear();
        }
        cout << a[0] << endl;
    }
}