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 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;
    string s = "";
    for(int i = n ; i > 0 ; i--) s += '0' + i;

    int p , c;
    rep(i , r){
      string t = "";
      cin >> p >> c;
      int pos = p - 1;

      for(int j = pos ; j < pos + c ; j++)
        t += s[j];

      s.erase(pos , c);
      t += s; s = t;
     }
    cout << s[0] << endl;
  }

  return 0;

}

C++: #include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;

#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;

int main() {
  while (true) {
    int n, l;
    cin >> n >> l;
    if (n == 0) break;
    int cards[2][n];
    for (int i = n; i > 0; i--) {
      cards[0][n-i] = i;
      cards[1][n-i] = 0;
    }

    for (int i = 0; i < l; i++) {
      int p, c;
      cin >> p >> c;
      for (int j = p-1; j < p+c-1; j++) {
	cards[(i+1)%2][j-p+1] = cards[i%2][j];
      }
      for (int j = 0; j < p; j++) {
	cards[(i+1)%2][c+j] = cards[i%2][j];
      }
      for (int j = p+c-1; j < n; j++) {
	cards[(i+1)%2][j] = cards[i%2][j];
      }
    }
    cout << cards[(n+1)%2][0] << endl;
  }
}

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-1;
		}
		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++: #define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
using namespace std;
int main(){

	int n,r;
	
	while(cin>>n>>r,n!=0||r!=0){
	stack<int> q;
	stack<int> a;
	stack<int> b;
		for(int i=1;i<=n;i++)
		q.push(i);
		int c,p;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			for(int j=1;j<p;j++){
			a.push(q.top());
				q.pop();
			}
			
			for(int j=0;j<c;j++){
			b.push(q.top());
				q.pop();
			}
			while(a.empty()!=true){
				q.push(a.top());
				a.pop();
			}
			while(b.empty()!=true){
				q.push(b.top());
				b.pop();
			}
		}
		cout<<q.top()<<endl;
	}
}

C++: #include<cmath>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cstdio>
#define rep(i,n) for(int i=0;i<n;i++)
#define fori(i,k,n) for(int i=k;i<n;i++)
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };



int main()
{
	int r, l;
	cin >> l >> r;
	while (1)
	{
		if (l == r&&r == 0)break;
		vector<int> h;
		for (int i = l; i >=1; i--)h.push_back(i);
		for (int i = 0; i < r; i++)
		{
			vector<int> now;
			int p, c;
			cin >> p >> c;
			for (int k = p - 1; k < p - 1 + c; k++)
			{
				now.push_back(h[k]);
			}
			for (int k = 0; k < p - 1; k++)
			{
				now.push_back(h[k]);
			}
			for (int k = p - 1 + c; k < h.size(); k++)
			{
				now.push_back(h[i]);
			}
			for (int k = 0; k < h.size(); k++)
			{
				h[k] = now[k];
			}
		}
		cout << h[0] << endl;
		cin >> l >> r;
	}

	return 0;
}

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

int main(){
  int card[50],tmp[50];
  int n,r,p,c;

  while(cin >> n >> r,n){
    for(int i=0;i<n;i++)card[i] = n-i;

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

      for(int i=0;i<c;i++)tmp[i] = card[p-1+i];
      for(int i=p-2;i>=0;i--)card[i+c] = card[i];
      for(int i=0;i<c;i++)card[i] = tmp[i];
    }
    cout << card[0] << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#define N 50
using namespace std;

int main(){

  int n,r,ans;
  int operate[N][2];

  while(true)
    {
      cin >> n >> r;
      if(n == 0 && r == 0)break;

      for(int i=0;i<r;i++)cin >> operate[i][0] >> operate[i][1];
      ans = n;
      int da = n;
     
      for(int i=r-1;i>=0;i--){

	if(n - ans  +1<= operate[i][1]){
	  ans -= operate[i][0] -1;
	}else if(n-ans+1< operate[i][0]+operate[i][1]) 
	  {
	    ans += operate[i][1];
	  }


	//	da = n;
	/*	if(n-operate[i][1] <= ans && ans <= n)
	  {
	    if(n == operate[i][1])continue;
	    ans = ans-operate[i][0]+1;
	  
	  }
	else{
	  da = da-operate[i][0]+1;
	  if(da <= ans)ans+=operate[i][1];
	  //else if(da > ans)ans-=operate[i][1];

	}
	*/
	//cout << "da ~ " << da << endl;
	//cout << "ans = " << ans << endl;

      }

      cout << ans << endl;



    }

}

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] = after[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;
}