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;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n,r;

int main(){
	while(cin >> n >> r && n+r){
		vector<ll> v(n);
		rep(i,n)v[i] = n-i;
		rep(i,r){
			ll p,c;
			vector<ll> vv;
			cin >> p >> c;
			p--;
			rep(i,c)vv.push_back(v[p+i]);
			rep(i,n){
				if(i < p || i >= p+c)vv.push_back(v[i]);
			}
			v.clear();
			v = vv;
		}
		cout << v[0] << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

int main()
{
    int n,r;
    int p,c;
    int move[55]={};
    int keep[55]={};
    while(1==1)
    {
        scanf("%d %d\n",&n,&r);
        REP(i,n)move[i]=n-i;
        if(n==0 && r==0)break;
        REP(i,r)
        {
            scanf("%d %d\n",&p,&c);
            REP(j,n)keep[j]=move[j];
            REP(j,c)move[j]=keep[j+p-1];
            for(int j=c;j<c+p-1;j++)move[j]=keep[j-c];
            //REP(j,n)printf("%d ",move[j]);
            //printf("###\n");
        }
        printf("%d\n",move[0]);
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
struct num{
  int c,p;
};
std::vector<int> push(std::vector<int> recv,int p,int c){
  std::vector<int> vec;
  for(int i=p-1;i<=p+c-2;++i){
    vec.push_back(recv[i]);
  }
  return vec;
}
std::vector<int> cp(std::vector<int> recv,std::vector<int> recv2){
  std::vector<int> vec;
  for(int i=0;i<recv.size();++i){
    vec.push_back(recv[i]);
  }
  for(int i=0;i<recv2.size();++i){
    vec.push_back(recv2[i]);
  }
  return vec;
}
int main(){
    int n,r;
    while(std::cin>>n>>r,n!=0){
    std::vector<num> vec;
    std::vector<int> f;
    for(int i=0;i<n;++i){
      f.push_back(n-i);
    }
    for(int i=0;i<r;++i){
      num n;
      std::cin>>n.p>>n.c;
      vec.push_back(n);
    }
    for(int i=0;i<vec.size();++i){
      std::vector<int> vec2;
      vec2=push(f,vec[i].p,vec[i].c);
      f=cp(vec2,f);
    }
    std::cout<<f[0]<<std::endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

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

C++: #include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;
int n,r;
int p,c;
vector<int> card;
vector<int> tmp;
int main(){
  while(true){

    cin >> n >> r;
    if(n==0&&r==0)break;
    card.resize(n);
    REP(i,n)card[i]=i+1;
    REP(i,r){
      cin >> p >> c;
      for(int j=n-p+1;j<n-p+1+c;j++)
	tmp.push_back(card[j-c]);
      for(int j=n-p+1;j<n;j++){
    card[j-c] = card[j];
      }
      /*      REP(k,n)cout << card[k] << " ";
	      cout << "\n";*/
    if(p!=1)
      for(int j=n-c;j<n;j++)
        card[j] =tmp[j-n+c];
    /*      REP(k,n)cout << card[k] << " ";
	    cout << "\n";*/
      tmp.clear();
    }
    cout << card[n-1] << endl;
    card.clear();

  }

  return 0;
    
}

C++: #include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

int main(){
    int n, r;
    while(cin>>n>>r&&n){
        vector<int> line(n);
        REP(i, n)line[i]=n-i;
        REP(i, r){
            int p, c;
            cin >> p >> c;
            vector<int> nl(line.begin()+p-1, line.begin()+p+c-1);
            nl.insert(nl.end(), line.begin(), line.begin()+p-1);
            nl.insert(nl.end(), line.begin()+p+c-1, line.end());
            line=nl;
        }
        cout << line.front() << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <stack>

#define rep(i,x) for(int i=0;i<x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rep_to(a,i,x) for(int i=a;i<x;i++)

using namespace std;

int main()
{
	int n,r;

	while(cin>>n>>r && n && r)
	{
		int card[100000]={};
		for(int i=n,j=1;i>=1;i--,j++)card[j]=i;
		rep(i,r)
		{
			int p,c;
			cin>>p>>c;
			for(int j=p;j>1;j--)
			{
				//cout<<j<<endl;
				for(int k=j;k<c+j;k++)
				{
					swap(card[k],card[k-1]);
					/*
					cout<<"swap:"<<k<<" "<<k-1<<endl;
					rep_to(1,l,n+1)cout<<card[l]<<" ";
					cout<<endl;
					*/
				}
			}
		}
		cout<<card[1]<<endl;
	}
	return 0;
}