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 n[10000]={},r[10000]={};
int p[10000][50] = {};
int c[10000][50] = {};
int i=0;

int d[50]={};
int e[50] = {}; //今の状態
int e2[50] = {};

int main(){
    while(1){
        scanf("%d %d",&n[i],&r[i]);
        if(n[i]== 0 && r[i]== 0){
            break;
        }
        for(int j=0;j<r[i];j++){
            scanf("%d %d",&p[i][j],&c[i][j]);
        }
        i++;
    }
    int times = i;
    for(i=0;i<times;i++){
        //初期化
        int s=0;
        for(int k = n[i]; k>0;k--){
            e[s] = k;
            s++;
        }
        for(int j=0;j<r[i];j++){
            s=0;
            for(int t=p[i][j]-1;t<p[i][j]+c[i][j]-1;t++){
                d[s] = e[t];
                s++;
            }
            for(int t = 0;t < n[i];t++){
                e2[t] = e[t];
            }
            for(int t = 0;t<c[i][j];t++){
                e[t] = d[t];
            }
            s = 0;
            for(int t=c[i][j];t<p[i][j]+c[i][j]-1;t++){
                e[t] = e2[s];
                s++;
            }
            for(int t=0;t<n[i];t++){
                cout<<e[t]<<endl;
            }
            puts("");

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

    return 0;
}

C++: #include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(v) (v).begin(),(v).end()

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    while(1){
        int n;
        vector<int> vec;
        cin >> n;
        rep(i,n){
            vec.push_back(n-i);
        }
        int r;
        cin >> r;
        if(n == 0){
            break;
        }
        rep(i,r){
            int a,b;
            cin >> a >> b;
            vector<int> up;
            vector<int> bf;
            for(int i = a-1;i<a+b-1;i++){
                up.push_back(vec[i]);
            }
            rep(i,up.size()){
                bf.push_back(up[i]);
            }
            rep(i,a-1){
                bf.push_back(vec[i]);
            }
            for(int i = a+b-1;i < n;i++){
                bf.push_back(vec[i]);
            }
            vec.clear();
            vec = bf;
        }
        cout << vec[0] << "\n";
    }
	return 0;
}

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

using namespace std;

vector<int> data;

void shuffle(int p,int c){
  vector<int> tmp(c);
  for(int i=0;i < c;i++){
    tmp[i] = data[p+i];
  }
  data.erase(data.begin()+p, data.begin()+p+c);
  for(int i=0;i < c;i++){
    data.push_back(tmp[i]);
  }
}

int main(){
  int n, r, p, c;
  while(1){
    cin>> n >> r;
    if(!n && !r) break;
    data.reserve(n+1);
    for(int i=1;i<=n;i++){
      data.push_back(i);
    }
    for(int i=0;i<r;i++){
      cin>> p >> c;
      shuffle(p-1,c);
    }
    cout << data[data.size()-1] << endl;
    data.clear();
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<queue>
#include<map>
#define pb push_back
#define INF 1000000000

using namespace std;
int main(){
	int n,r;
	while(cin>>n>>r,n||r){
		vector<int> v(n);
		for(int i=0;i<n;i++){
			v[i]=n-i;
		}
		
		int p,c;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			vector<int> x;
			for(int j=0;j<p-1;j++){
				x.pb(v[j]);
			}
			vector<int> y;
			for(int j=p-1;j<c+p-1;j++){
				y.pb(v[j]);
			}
			for(int j=0;j<c;j++){
				v[j]=y[j];
			}
			for(int j=c;j<c+p-1;j++){
				v[j]=x[j-c];
			}
		}
		cout<<v[0]<<endl;
	}
	return 0;
}

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

int hanafuda[51], tmp[51];

int main()
{
    int n,c,p,r;
    while(cin >> n >> r && n && r) {
        for(int i = 0; i < n; i++)
            hanafuda[i] = i + 1;
        
        for(int i = 0; i < r; i++) {
            cin >> p >> c;
            
            for(int j = 0; j < c; j++) 
                tmp[c - 1 - j] = hanafuda[n - p - j];
            
            for(int j = n - p + 1; j < n; j++)
                hanafuda[j - c] = hanafuda[j];

            for(int j = 0; j < c; j++)
                hanafuda[n - c + j] = tmp[j];

        }
        cout << hanafuda[n - 1] << endl;
    }
}

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

//constant
const int inf=1<<28;

//variable
int n,r;
int p,c;


int main(){
    while(cin>>n>>r,r){
        deque<int> pile;
        for(int i=0; i<n; i++){
            pile.push_front(i+1);
        }
        for(int i=0; i<r; i++){
            cin>>p>>c;
            deque<int> temp;
            for(int i=0; i<c; i++){
                temp.push_front(*(pile.begin()+p-1));
                pile.erase(pile.begin()+p-1);
            }
            while(!temp.empty()){
                pile.push_front(temp.front());
                temp.pop_front();
            }
        }
        /*cout<<endl;
        for(auto it=pile.begin(); it!=pile.end(); it++){
            cout<<*it<<endl;
        }
        cout<<endl;*/
        cout<<pile.front()<<endl;
    }

    return 0;
}

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

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

const int MAXN = 50;

int main()
{
    int n, r, c, p;
    int before[MAXN];
    int after[MAXN];

    while(cin >> n >> r && (n || r))
    {
        REP(n) { before[i] = after[i] = n - i;}
        
        rep(k,r)
        {
            cin >> p >> c;
            
            for(int i = 0;i < c; i++)
                after[i] = before[i + p - 1];

            for(int i = 0;i < p - 1; i++)
                after[i + c] = before[i];

            REP(MAXN) before[i] = after[i];
        }
        cout << after[0] << endl;

    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int index[51];
int main(){
  int n,r;
  while(cin>>n>>r,n+r){
    for(int i=0;i<n;++i) index[i]=n-i;
    int p,c;
    for(int k=0;k<r;++k){
      cin>>p>>c;
      int cnt=0;
      while(cnt!=c){
	int tmp=index[p-1+cnt];
	for(int j=0;j<p-1;++j)
	  index[p-j+cnt]=index[p-j-1+cnt];
	index[0]=tmp;
	++cnt;
      }
    }
    cout<<index[0]<<endl;
  }
  return 0;
}

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

int main() {
	int n, r;
	while(cin >> n >> r, n || r) {
		vector<int> v(n);
		iota(v.rbegin(), v.rend(), 1);
		
		for(int i = 0; i < r; ++i) {
			int p, c;
			cin >> p >> c;
			p--;
			auto temp = v;
			for(int j = 0; j < c; ++j) {
				temp[j] = v[p + j];
			}
			
			for(int j = 0; j < p; ++j) {
				temp[c + j] = v[j];
			}
			
			swap(v, temp);
		}
		cout << v[0] << endl;
	}
	return 0;
}