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;

#define FOR(i,s,e) for(int (i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define UNIQUE(o) (o).erase(unique(sort(all((o)))))

typedef long long ll;
const int N = 50;
int n, r, p, c;
int a[N][2];

int main() {
  while (1) {
    scanf("%d%d ", &n, &r);
    if (!n) break;
    REP(i,n) a[n-1-i][0] = i+1;
    int crt, nxt;
    REP(i,r) {
      crt = i&1, nxt = (i+1)&1;
      scanf("%d%d ", &p, &c);
      p--;
      REP(j,c) a[j][nxt] = a[p+j][crt];
      REP(j,p) a[j+c][nxt] = a[j][crt];
      FOR(j,p+c,n) a[j][nxt] = a[j][crt];
    }
    printf("%d\n", a[0][nxt]);
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#define REP(i,a,e) for(int i=(a);i<(e);++i)
using namespace std;
int main(){
	while(true){
		int n;
		int r;
		vector<int> v1,v2;
		cin>>n>>r;
		if(n==0&&r==0)break;
		v1.resize(n);
		REP(i,0,n){
			v1[n-1-i]=i+1;
		}
		REP(i,0,r){
			int p,c;
			cin>>p>>c;
			v2=v1;
			--p;
			v1.insert(v1.begin(),v2.begin()+p,v2.begin()+p+c);
			v1.erase(v1.begin()+c+p,v1.begin()+c+p+c);
		}
		cout << v1[0] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
  int maisu[50];
  int katto;
  int swap[50];
  int p,c;
  int i;
  for(i=0; i<50; i++){
    maisu[i] = i;
  }
  cout << maisu[0] << endl;
  cin >> katto;
  // while(j <= katto){
    while(true){
      scanf("%d%d",&p,&c);
      if(p == 0 && c == 0){break;}
      for(i=0; i<c; i++){
	swap[i] = maisu[i + p-1];
      }
      for(i = 0; i<p-1; i++){
	swap[i+c] = maisu[i];
      }
      for(i=0;i<p+c-1; i++){
	maisu[i] = swap[i];
      }
    }
    // if(p == 0 && c == 0){
	// break;
    // }
  // }
    cout << maisu[0] << endl;
    return 0;
}

C++: #include<iostream>
#define N 50
using namespace std;
/*
Hanafuda Shuffle
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1129&lang=jp

*/
int array[N];
void makearray(int n){
    for(int i=0;i<N;i++){
	array[i]=n;
	if(n>0)n-=1;
    }
}
void shuffle(int p, int c){
    int sarray[N];
    //copy unshuffled deck
    for(int i=p-1+c;i<N;i++){
	sarray[i]=array[i];
    }
    //copy the c part
    int j=0;
    for(int i=p-1;i<p-1+c;i++){
	sarray[j]=array[i];
	j++;
    }
    // copy the p part
    j=c;
    for(int i=0;i<p-1;i++){
	sarray[j]=array[i];
	j++;
    }
    for(int i=0;i<N;i++){
	array[i]=sarray[i];
    }
}
    
    
    
int main(){
    int n,r, p, c;
    while(1){
	cin >>n>>r;
	makearray(n);
	if(n==0 && r==0)break;
	for(int i=0;i<r;i++){
	    cin >> p>>c;
	    shuffle(p,c);
	}
	cout << array[0] << endl;
    }
    
}

C++: #include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

ll v[100];

int main()
{
	cin >> n >> k;
	if (n == 0 && k == 0) {
		return 0;
	} else {
		fill(v, v + 100, 0);
		REP(i, n)
		{
			v[i + 1] = i + 1;
		}
		REP(i, k)
		{
			ll a, b;
			cin >> a >> b;
			ll temp[100];
			REP(j, n + 1) temp[j] = v[j];
			fill(v, v + 100, 0);
			FOR(j, 1, a - b + 1)
			{
				v[j] = temp[j];
			}
			FOR(j, a - b + 1, n + 1 - b)
			{
				v[j] = temp[j + b];
			}
			FOR(j, n - b + 1, n + 1)
			{
				v[j] = temp[j - n + b - 1 + a - b + 1];
			}
		}
	}
	cout << v[n] << endl;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll tmp1[55];

int main(void){
	int n,r;
	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++){
			int p,c;
			cin>>p>>c;
			for(int i=p-1;i<p+c-1;i++){
				tmp1[i-p+1]=a[i];
			}
			for(int i=p-2;i>=0;i--){
				a[i+c]=a[i];
			}
			for(int i=0;i<c;i++){
				a[i]=tmp1[i];
			}
		}
		cout<<a[0]<<endl;
	}
    return 0;
}

C++: #include <cstdio>

using namespace std;

int n, r;
int cards[2][51];

int main() {
  while (true) {
    scanf("%d %d", &n, &r);
    if (n == 0 && r == 0) break;
    for (int i=0;i<n;i++) cards[0][i] = n-i;
    for (int i=0;i<r;i++) {
      int p, c;
      scanf("%d %d", &p, &c);
      for (int j=0;j<c;j++) {
        cards[(i+1)&1][j] = cards[i&1][p-1+j];
      }
      for (int j=0;j<p-1;j++) {
        cards[(i+1)&1][c+j] = cards[i&1][j];
      }
      for (int j=p-1+c;j<n;j++) {
        cards[(i+1)&1][j] = cards[i&1][j];
      }
    }
    printf("%d\n", cards[r&1][0]);
  }
}

C++: #include <iostream>
using namespace std;
int n, r;
int p, c;
int a[100], tmp[100];

int main(void) {
    while(1) {
        cin >> n >> r;
        if(n==0 && r==0) break;
        for(int i=0; i<n; i++)
            a[i] = n - i; 
        
        for(int i=0; i<r; i++) {
            cin >> p >> c;
            for(int j=p-1; j<p-1+c; j++) {
                tmp[j-p+1] = a[j];
            }
            for(int j=c; j<n; j++) {
                tmp[j] = a[j-c];
            }
            for(int j=0; j<n; j++)
                a[j] = tmp[j];
        }
        cout << a[0] << endl;       
    }
    return 0;
}