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 <bits/stdc++.h>
using namespace std;

int main(){
	int n, r;
	int p, c;
	vector<int> huda, temp;
	vector<int>::iterator itr;
	
	cin >> n >> r;
	for(int i=0; i<n; i++) huda.push_back(i+1);
	
	while(n!=0 && r!=0){
		for(int i=0; i<r; ++i){
			cin >> p >> c;
			
			for(int j=0; j<c; ++j){
				itr = huda.begin()+(n-p-j);
				temp.push_back(*itr);
				huda.erase(itr);
			}
			for(int j=c-1; j>=0; --j){
				itr = temp.begin()+j;
				huda.push_back(*itr);
			}
			
			temp.clear();
		}
		cout << *(huda.begin()+n-1) << endl;
		
		cin >> n;
		cin >> r;
		huda.clear();
		for(int i=0; i<n; i++) huda.push_back(i+1);
	}
	return 0;
}

C++: #include <iostream>

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

int main(void){

	int n, r;		//山の枚数、回数
	int p, c;		//上からの何枚目、枚数
	int n1[50];	//山
	int temp[50];	//一時的に保存しておく
	int ans[50];	//答えを保存しておく
	int j=0;		//答えを格納する時に使う

	while(std::cin >> n >> r, n || r){		//n,rを取得０、０でなければループ

		rep(i,n){
			n1[i] = n-i;						//n1[n] = {n,n-1,n-2,.........,1}
		}

		rep(i,r){

			std::cin >> p >> c;				//p,cを取得
			rep(i, c){
				temp[i] = n1[p-1+i];
			}
			rep(i, p-1){
				n1[p-1-i+c] = n1[p-1-i];
			}

			rep(i,c){
				n1[i] = temp[i];
			}
		}
		std::cout << n1[0] << std::endl;
		//ans[j++] = n1[0];
	}

	/*
	rep(i,j){
		std::cout << ans[i] << std::endl;
	}
	*/
	return 0;
}

C++: #include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
struct ml{
  int dt;
  struct ml *nx;
};
typedef struct ml Ml;
void f(Ml *a,int p,int q){
  int i;
  Ml *b,*c,*d;
  b=a;
  for(i=0;i<p-1;i++)
    b=b->nx;
  c=b;
  for(i=0;i<q;i++)
    c=c->nx;
  d=a->nx;
  a->nx=b->nx;
  b->nx=c->nx;
  c->nx=d;
  return;
}
int main(){
  int i;
  int n,r,p,q;
  Ml *a;
  while(cin>>n>>r&&n+r){
    a=(Ml*)malloc((n+2)*sizeof(Ml));
    for(i=0;i<n+1;i++){
      (a+i)->dt=n-i+1;
      (a+i)->nx=a+i+1;
    }
    (a+i)->dt=n-i+1;
    for(i=0;i<r;i++){
      cin>>p>>q;
      if(p!=1)
	f(a,p,q);
    }
    cout<<a->nx->dt<<endl;
    free(a);x
  }
  return 0;
}

C++: #include<bits/stdc++.h>

using namespace std;

int main(){
  

  while(1){
    int n,r;
    cin>>n>>r;

    if(n==0 && r==0)break;
    
    int x[n];

    int p,c,k=0;


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

    for(int j=1;j<=r;j++){
      
      cin>>p>>c;
      int y[p];
      int z[c];
      
      for(int i=0;i<p-1;i++){
	y[i]=x[n-p+1+i];
      }
      
      for(int i=0;i<c;i++){
	z[i]=x[n-p-c+1+i];
      }
      
      for(int i=0;i<c;i++){
	x[n-c+i]=z[i];
      }
      
      for(int i=0;i<p-1;i++){
	x[n-c-p+1+i]=y[i];
      }
    
      
    }
    
    
    cout<<x[n-1]<<endl;
    
    
  }
}

C++: #include <string>
#include <iterator>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>

using namespace std;

string GetStr()
{
	string str;
	getline(cin,str);
	return str;
}

vector<int> GetIntVector()
{
	string str;
	getline(cin,str);
	istringstream line( str );

	istream_iterator<int> iit(line);
	istream_iterator<int> iit_eof;

	vector<int> ret;

	for(;iit != iit_eof; iit++){
		ret.push_back(*iit);
	}

	return ret;
}

typedef struct 
{
	int n,count;
} HANAFUDA;

HANAFUDA GetSituation()
{
	HANAFUDA h;
	vector<int> v = GetIntVector();
	h.n = v[0];
	h.count = v[1];

	return h;
}

bool true_func(int dummy){return true;}

void solve(HANAFUDA h)
{
	vector<int> data(h.n);
	for(int i = 0; i < h.n; i++){
		data[i] = h.n - i;
	}

	for(int i = 0; i < h.count; i++){
		vector<int> inputs = GetIntVector();
		rotate( data.begin(), data.begin() +(inputs[0] - 1), data.begin() + (inputs[0] + inputs[1] - 1) );
	}

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

void Hanafuda()
{
	HANAFUDA h = GetSituation();
	while(h.n != 0 && h.count != 0){
		solve(h);
		h = GetSituation();
	}
}


int main()
{
	Hanafuda();

	return 0;
}

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

int main(){
	int n,r;
	while(cin>>n>>r &&n && r){
		vector<int>data;
		for(int i=1;i<=n;i++)data.push_back(i);
		for(int i=0;i<r;i++){
			int p,c;
			cin>>p>>c;
			stack<int>st;
			for(int j=0;j<c;j++){
				
				int tmp=data[n-p];
				data.erase(data.begin()+n-p++);
				st.push(tmp);
				
				}
			
			while(!st.empty()){
				data.push_back(st.top());st.pop();
			}
		}
		cout<<data[n-1]<<endl;
	}
}

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

//?±±?????????????????¢??°???????±±???????±±????????°n???p?????????????????????c???                       
void shuffle(vector<int> &yama, int n, int p, int c);


int main(){
  int n, r;
  int p, c;
  vector<int> yama, v;

  cin >> n;
  cin >> r;

  while(n != 0 && r != 0){
    //?±±??????????????????                                                            
    for(int i = 0, j = n; i < n; i++, j--){
      yama.push_back(j);
    }
    //?????£?????????                                                                
    for (int i = 0; i < r; i++){
      cin >> p;
      cin >> c;
      shuffle(yama, n, p, c);
    }
    //???????????????????¨????                                                          
    v.push_back(yama.front());

    cin >> n;
    cin >> r;
  }
  for(int i = 0; i < v.size(); i++){
    cout << v[i];
  }
  cout << endl;
}

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

int main(){
  int n,r,p,c;

  while(cin >> n >> r , n + r){
    vector<int> cards;

    for(int i = n ; i >= 1 ; i--){
      cards.push_back(i);
    }

    while(r--){
      cin >> p >> c;
      vector<int> tmp;
      for(int i = p-1 ; i < p+c-1 ; i++){
	tmp.push_back(cards[i]);
	cards[i] = -1;
      }
   
      for(int i = 0 ; i < cards.size() ; i++){
	if(cards[i] != -1) tmp.push_back(cards[i]);
      }

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

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

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

int main() {
	
	int n,r,p,c;
	
	while(1){
	cin>>n>>r;
	if(n==0&&r==0)return 0;
	int ca[50],d[50];
	for(int i=0;i<n;i++){ca[i]=n-i;d[i]=0;}
	
	for(int i=0;i<r;i++){
		cin>>p>>c;
		for(int j=0;j<p-1;j++)d[j]=ca[j];
		for(int j=0;j<c;j++)ca[j]=ca[p-1+j];
		for(int j=0;j<p-1;j++)ca[c+j]=d[j];
		cout<<endl;
	}
	}
}

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

using namespace std;
int main(){
    int n,r,p,c;
    while(true){
        cin >> n >> r;
        if(n==0 && r==0){
            break;
        }
        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);
            for (int i=0;i<n;i++){
            }
        }
        cout << a[0] << endl;
    }
}