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<stack>
#include<queue>

using namespace std;

void solve(stack <int> s , int r ){
  
  
  int p[r] ,c[r];

  for(int i = 0 ; i < r ; i++ ){
    cin >> p[i] >> c[i];
    p[i]--;
  }
  
  for(int i = 0 ; i < r ; i++ ){
    stack<int> s_sita;
    stack<int> s_ue;
    
    

    while(p[i]-- > 0){
      int a = s.top();
      s.pop();
      //cout << "push_sita:" << a << endl;
      //cout << "p:" << p[i] << endl;
      //cout << "size" << s.size() << endl;
      s_sita.push(a);
    }

    while(c[i]-- > 0){
      int a =s.top();
      s.pop();
      //cout << "push_ue:" << a << endl;
      //cout << "c" << c[i] << endl;
      //cout << "size" << s.size() << endl;
      s_ue.push(a);
    }
    
    while(!s_sita.empty()){
      s.push(s_sita.top());
      //cout << "s.push" << s_sita.top() << endl;
      s_sita.pop();
    }
    
    while(!s_ue.empty()){
      s.push(s_ue.top());
      //cout << "s.push" << s_ue.top() << endl;
      s_ue.pop();
    }
    
    //cout << "size" << s.size() << endl;

    //cout << endl;

  }
    
  cout << s.top() << endl;

  return;

}

int main(){

  int r , n ;

  
  while(1){

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

    else{
      stack <int> s;
      for(int i = 1 ; i <= n ; i++ ){
        s.push(i);
        //cout << i << endl;
      }
      solve(s,r);
      //cout << "done" << endl;
    }
  }

  return 0;
}

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

vector<int> cut(vector<int> crd,int p,int c){
  vector<int> ret = crd;
  for(int i=0;i<c;++i) ret[i] = crd[i+p];
  for(int i=0;i<p;++i) ret[c+i] = crd[i];
  return ret;
}

int main(){
  int n,k;
  while(cin>>n>>k,n||k){
    vector<int> crd;
    for(int i=n;i>=1;--i) crd.push_back(i);
    while(k--){
      int p,c;
      cin >> p >> c;--p;
      crd = cut(crd,p,c);
    }
    cout << crd[0] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
using namespace std;

int n,r,p,c;
int before[50],after[50];

void init(){
	for(int i=0;i<50;i++)
		before[i]=after[i]=0;
}

bool input(){	
	int i;
	cin>>n;
	cin>>r;
	if((n==0) && (r==0))
		return false;
	for(i=0;i<n;i++)
		before[i]=n-i;
		after[i]=n-i;
	return true;
}

void Shuffle(int b[], int a[]){
	int j;
	for(j=0;j<c;j++)
		a[j]=b[p-1+j];
	for(j=0;j<p-1;j++)
		a[c+j]=b[j];
	for(j=0;j<n;j++)
		b[j]=a[j];
}


int solve(){
	for(int i=0;i<r;i++){
		cin>>p>>c;
		Shuffle(before,after);
	}
	return after[0];
}


int main(){
  while(init(),input()){
	cout<<solve()<<endl;
  }
  return 0;
}

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

using namespace std;

int N, R, p, c, i, j;
int A[N] = {};

int main()
{
   while ( cin >> N >> R && N >0 )
   {
      for ( i = 0; i < N; i++)
         {
            A[i] = N - i;
         }
      for ( j = 0; j<R; j++)
         {
            cin >> p >> c;
            rotate(A,A+(p-1),A+(p+c-1))
         }
      cout << A[0] <<endl;
   }
}

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

using namespace std;

int main(){
	int n, r;
	
	while(cin >> n >> r, n | r){
		vector<int> p, c;
		int tempp, tempc;
		vector< vector<int> > deck;
		
		deck.resize(r + 1);
		for(int i = 0; i <= r; i++){
			deck[i].resize(n);
		}
		
		for(int i = 0; i < n; i++){
			deck[0][i] = n - i;
		}
		
		for(int i = 0; i < r; i++){
			cin >> tempp >> tempc;
			p.push_back(tempp);
			c.push_back(tempc);
		}
		
		for(int i = 1; i <= r; i++){
			int count = 0;
			for(int j = p[i - 1] - 1; j < p[i - 1] + c[i - 1] - 1; j++){
				deck[i][count] = deck[i - 1][j];
				count++;
			}
			for(int k = 0; k < p[i - 1] - 1; k++){
				deck[i][count] = deck[i - 1][k];
				count++;
			}
			for(int l = p[i - 1] + c[i - 1] - 1; l < n; l++){
				deck[i][count] = deck[i - 1][l];
				count++;
			}
		}
		
		cout << deck[r][0] << endl;
	}
	
	return 0;
}

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

int main(){
  while(1){
    int n,r;
    std::cin>>n>>r;
    if(n==0&&r==0) break;
    std::vector<int> hanafuda(n),tmp(n);
    for(int i=0;i<n;++i) hanafuda[i]=n-i;

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

C++: #include<iostream>
using namespace std;
int main(){
    int n,r,p,c;
    while(true){
        cin>>n>>r;
        if(n==0&&r==0){
            break;    
        }else{
            int A[n];
            for(int i=0;i<n;i++){
                A[i]=n-i;   
            }
            for(int j=0;j<r;j++){
                cin>>p>>c;
                int B[p-1];
                for(int i=0;i<p-1;i++){
                    B[i] = A[i];  
                }
                for(int i=0;i<c;i++){
                    A[i]=A[p-1+i];   
                }
                for(int i=0;i<p-1;i++){
                    A[c+i]=B[i];   
                }
            }
            cout<<A[0]<<endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <list>
#define rep(i,n) for(int i = 0; i < n;i++)

using namespace std;
int main(int argc, const char * argv[]){
    int n,r;
    int p,c;
    int A[100];
    while(cin >> n >> r && n){
        for(int i=0;i < n;i++){
            A[i]=n-i;
        }
        for(int i = 0;i < r;i++){
            cin >> p >> c;
            rotate(A,A+p-1,A+p+c-1);

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

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,r,p,c;
  while(cin>>n>>r&&n){
    vector<int> A(n);
    for(int i=0;i<n;i++) A[i]=n-i;
    for(int i=0;i<r;i++){
      cin>>p>>c;
      rotate(A.begin(),A.begin()+p-1,A.begin()+p+c-1);
    }
    cout<<A[0]<<endl;
  }
}

C++: #include <stdio.h>

int main(void){
  int n, r, p, c, i;
  while(1){
    scanf("%d%d", &n, &r);
    if (n==0 && r==0){
      break;
    }
    int card[n], temp[n];
    for(i=0;i<n;i++){
      card[i] = n-i;
    }
    for(i=0;i<r;i++){
      scanf("%d%d", &p, &c);
      //カットの処理
      for(i=p-1;i<p+c-1;i++){
        temp[i-p+1] = card[i];
      }
      for(i=0;i<p-1;i++){
        card[p+c-2-i] = card[p-2-i];
      }
      for(i=0;i<c;i++){
        card[i] = temp[i];
      }
    }
    printf("%d", card[0]);
  }
  return 0;
}