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;

vector<int> data;

void shuffle(int p,int c){
  vector<int> tmp(c);
  int pos = data.size() - p - c + 1;
  for(int i=0;i < c;i++){
    tmp[i] = data[pos+i];
  }
  data.erase(data.begin()+pos, data.begin()+pos+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,c);
    }
    cout << data[data.size()-1] << endl;
    data.clear();
  }
  return 0;
}

C++: // {{{ include and macros
#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(a, b) for(int unsafe_cnt=a; unsafe_cnt < b;unsafe_cnt++)
#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;
// }}}

// {{{ put
void newline() {cout << endl;}
template <typename T> void display(T input){cout << input;}
template <typename T> void put(T input){display(input); newline();}
// }}}

vector<int> to_top(const vector<int> v
                  ,const int p   // ???????§????
                  ,const int c){
  vector<int> w;
  for(int i=p; i<p+c; i++){
    w.push_back(v[i]);
  }
  for(int i=0; i<v.size(); i++){
    if(!(p<=i && i<p+c)){
      w.push_back(v[i]);
    }
  }
  return w;
}

int main() {
  int n, r;
  cin >> n >> r;
  vector<int> v;
  for(int i=n; i > 0; i--){v.push_back(i);}
  for(int i=0;i<v.size();i++){display(v[i]);display(" ");} put("");
  for(int i=0; i < r; i++){
    int p, c;
    cin >> p >> c;
    v = to_top(v, p-1, c);
    for(int i=0;i<v.size();i++){display(v[i]);display(" ");}put("");
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#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 = 52;
int before[MAXN], after[MAXN];

int main()
{
    int n, r, p, c;
    while(cin >> n >> r && (n || r))
    {
        for(int i = n; i > 0;i--) before[n - i] = i;

        rep(j,r)
        {
            cin >> p >> c;
            
            REP(p - 1) after[c + i] = before[i];
            REP(c) after[i] = before[i + p - 1];

            REP(n) before[i] = after[i];
        }


        cout << before[0] << endl;
    }
    return 0;
}

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

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

C++: #include "bits/stdc++.h"

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b == 0) return b;
  else gcd(b, a%b);
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b))*b;
}

struct UnionFind {
  vi par; //par[i] : iの親番号（例）par[3] = 2 : 3の親は2

  UnionFind(int N) : par(N) { //最初は全てが根として初期化
    rep(i,N) par[i] = i;
  }

  int root(int x){ //データxが属する木の根を再帰で得る : root(x) = {xの木の根}
    if(par[x] == x)return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){ //xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if(rx == ry)return; //xとyの根が同じ
    par[rx] = ry; //xとyの根が同じでない時、xの根rxをyの根にryにつける。
  }

  bool same(int x, int y){//2つのデータx，yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main(){

  int n,r;

  while(cin >> n, n){
    cin >> r;
    vi v(n,0);
    vi copy(n,0);
    rep(i,n) v[i] = n - i;

    int p , c;
    rep(i , r){
      vi v2;
      cin >> p >> c;
      int pos = p - 1;

      for(int j = pos ; j < pos + c ; j++){
        v2.pb(v[j]);
        v[j] = 0;
      }

      rep(j,v2.size())
        copy[j] = v2[j];

      for(int j = v2.size();j < n; j++){
        rep(k,n){
          if(v[k] != 0){
            copy[j] = v[k];
            v[k] = 0;
            break;
          }
        }
      }

      rep(j,n)
        v[j] = copy[j];

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

  return 0;

}

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

int main(){
  int n,r;
  int array1[50],array2[50];

  while(1){
    cin>>n>>r;
    if(n+r==0)break;

    for(int i=0;i<n;i++) array1[n-i-1]=array2[n-i-1]=i+1;

    for(int j=0;j<r;j++){
      int c,p;
      cin>>c>>p;

      for(int i=0;i<p;i++){
	swap(array1[c-1+i],array1[i]);
	array2[c-1+i]=0;
      }
      int k=p;
      for(int i=0;i<n;i++){
	while(array2[i]==0) i++;
	array1[k++]=array2[i];
      }
      for(int i=0;i<n;i++){
	//	while(array2[i]==0)i++;
	array2[i]=array1[i];
      }
      //      for(int i=0;i<n;i++) cout<<array1[i]<<endl;     
    }

    cout<<array1[0]<<endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
    int n, r;
    int p, c;
    r = 0;
    vector<int> card;
    vector<int> reserve;
    while (true) {
        if (r == 0) {
            cin >> n >> r;
            if (n == 0 && r == 0)
                break;
            for (int i = 0; i < n; i++) {
                card.push_back(i + 1);
            }
            continue;
        }
        cin >> p >> c;
        for (int i = n - p + 1; i < n; i++) {
            reserve.push_back(card.at(i));
        }
        for (int i = n - (p - 1) - c; i < n - (p - 1); i++) {
            reserve.push_back(card.at(i));
        }
        {
            int j = 0;
            for (int i = n - (p - 1) - c; i < n; i++) {
                card.at(i) = reserve.at(j);
                j++;
            }
        }
        reserve.clear();
        reserve.shrink_to_fit();
        r--;
        if (r == 0) {
            cout << card.at(n - 1) << endl;
            card.clear();
            card.shrink_to_fit();
        }
    }
}

C++: #include<cstdio>
using namespace std;
int num1[50],num2[50];
void sets(int N);
void change(int p,int c);
int main()
{
    int N,r,i,j,p,c;
    for(;scanf("%d%d",&N,&r),N+r!=0;)
    {
        sets(N);
        for(i=0;i<r;i++)
        {
            scanf("%d%d",&p,&c);
            change(p,c);
        }
        printf("%d\n",num2[0]);
    }
    return 0;
}
void sets(int N)
{
    for(int i=0,j=N;i<N;i++,j--)
    {
        num1[i]=j;
    }
}
void change(int p,int c)
{
    int i;
    for(i=0;i<p-1;i++)num2[c+i]=num1[i];
    for(i=0;i<c;i++)num2[i]=num1[p-2+i];
}