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>
using namespace std;


void shuffle(int a, int b, int *ans)
{
    int t[a];
    a--;
    for (int i = 0; i < a; i++) {
        t[i] = ans[i];
    }
    for (int i = a; i < a + b; i++) {
        ans[i - b] = t[i - e];
    }
    for (int i = b; i < a + b; i++) {
        ans[i] = t[i - b];
    }
}
int main()
{
    int n,r;
    while (cin >> n >> r, n) {
        int ans[n];
        for (int i = 0; i < n; i++) {
            ans[i] = n - i;
        }
        for (int i = 0; i < r; i++) {
            int b, e;
            cin >> b >> e;
            shuffle(b, e, ans);
        }
        cout << ans[0] << endl;

    }

    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
using namespace std;

int n,r,p,c;
int before[50],after[50],tmp[50];

void init(){
	for(int i=0;i<50;i++){
		after[i]=0;
		tmp[50]=0;
	}
}

bool input(){	
	int i;
	cin>>n>>r;
	for(i=0;i<n;i++)
		before[i]=i+1;	
	return 1;
}



int solve(){
	int j;
	for(int i=0;i<r;i++){
		cin>>p>>c;
		for(j=0;j<c;j++){
			after[n-1-j]=before[n-p-j];
			tmp[n-1-j]=before[n-p-j];
		}
		for(j=0;j<p;j++){
			after[n-1-c-j]=before[n-1-j];
			tmp[n-1-c-j]=before[n-1-j];
		}
		for(j=0;j<n;j++)
			before[j]=tmp[j];
	}
	return after[n-1];
}


int main(){
	n=r=1;
  while((n!=0)&&(r!=0)){
	init(),input();
	cout<<solve()<<endl;
  }
  return 0;
}

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

#define rep(i,n) for (int i = 0; i < int(n); ++i)

int n,r,p,c,a[50];

int main() {
  while (cin >> n >> r && n != 0 && r != 0) {
    rep (i,n) a[i] = n-i;
    rep (i,r) {
      cin >> p >> c;
      rotate(a, a+p-1, a+p-1+c);
    }
    cout << a[0] << endl;
  }
}

C++: #include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;


int main(){
	while(1){
		int n,r,p,c;
		cin>>n>>r;
		if(n==0)break;
		int ans=0;
		vl s(110),t(110);
		rep(i,1,n+1)s[i]=n-i+1;
		rep(i,0,r){
			cin>>p>>c;
			t=s;
			rep(j,1,p+c+1){
				if(j<=c)s[j]=t[p+j-1];
				else if(j>c&&j<p+c)s[j]=t[j-c];
			}
		}
		print(s[1]);
	}
	return 0;
}

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

void shuffle( vector <int>& deck, int p, int c )
{
    vector <int> cut( c );
    copy( deck.begin() + p - 1, deck.begin() + p + c - 1, cut.begin() );
    deck.erase( deck.begin() + p - 1, deck.begin() + p + c - 1 );
    deck.insert( deck.begin(), cut.begin(), cut.end() );
}

int main( void )
{
    int n, r;
    while ( cin >> n >> r && n && r )
    {
        vector <int> deck( n );
        for ( int i = 0; i < n; i++ ) deck[i] = n - i;

        int p, c;
        for ( int i = 0; i < r; i++ )
        {
            cin >> p >> c;
            shuffle( deck, p, c );
        }

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

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

int main()
{
  int n, r;
  for ( ; ; ) {
    cin >> n >> r;
    if (n == 0 && r == 0)
      break;

    vector<int> Card;
    for (int i = n; i > 0; --i)
      Card.push_back(i);

    for (int i = 0; i < r; ++i) {
      int p, c;
      cin >> p >> c;
      vector<int> Card_new;
      for (int j = 0; j < c; ++j) {
	Card_new.push_back(Card[p-1]);
	Card.erase(Card.begin() + p - 1);
      }
      for (unsigned int j = 0; j < Card.size(); ++j)
	Card_new.push_back(Card[j]);
      Card = Card_new;
    }
    cout << Card[0] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n||m){
    string in;
    rep(i,n)in=(char)(i+49)+in;

    rep(i,m){
      int a,b;
      cin>>a>>b;
      //cout<<in<<endl;
      in=in.substr(a-1,b)+in.substr(0,a-1)+in.substr(a+b-1);
    }
    cout<<in[0]-'0'<<endl;
  }

}

C++: arr=[]
ta=[]
while true do
  n, r = gets.split.map(&:to_i)
  if n == 0 && r == 0
    break
  end
  arr = (1..n).to_a.reverse
  r.times do
        p, c = gets.split.map(&:to_i)
        p -= 1
        ta = arr[p...p+c] + arr[0...p] + arr[p+c..n]
        arr = ta
  end
  puts arr[0]
end

C++: #include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
#define ll long long
#define pb push_back

int main()
{
    int n, r, j=0,c;
    vector<int> x;

    while (1)
    {
        cin >> n >> r;
        if (n == 0 || r == 0)
        {
            break;
        }
        vector<int> a(n);
        for(int i=1;i<=n;i++){ // a[n] を一番上とする
            a[i-1] = i;
        }
        int p,c;
        for (int i = 0;i<r;i++)
        {
            cin >> p >> c;
            for(int j = 0; j < c; j++){
                a.push_back(a[n-p-c+1]); // p番目を取り出す
                a.erase(a.begin()+(n-p-c+1));
            }
            // for(int i=0;i<n;i++){ // a[n] を一番上とする
            //     cout << a[i];
            // }
            // cout << endl;
        }
        x.push_back(a[n-1]);
        j++; 
    }
    for(int i=0;i<j;i++){
        cout << x[i] << endl;
    }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
using namespace std;

#define ll long long int
#define ld long long double
#define reps(i,f,n) for(int i=f;i<n;i++)
#define rep(i,n) reps(i,0,n)
#define m1 cout<<"move1"<<endl
#define m2 cout<<"move2"<<endl
#define m3 cout<<"move3"<<endl
#define m4 cout<<"move4"<<endl


int main(){
  ll N,R;
  vector<int> v;
  ll a,b;
  vector<int> c;
  
  while(cin>>N,cin>>R,N != 0 && R != 0){
    rep(i,N)v.insert(v.begin(),i);
    rep(i,R){
      cin>>a>>b;
      for(int i=a-1;i< a+b-1;i++) c.push_back(v[i]);
      v.erase(v.begin() + a - 1, v.begin() + a - 1 + b);
      for(int i=0;i < c.size();i++)v.insert(v.begin()+ i,c[i]);
      c.clear();
    }
    cout<<v[0] + 1 <<endl;
    v.clear();
  }
  return 0;
}

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

using namespace std;

int main(void){
  int n, r, p, c;
  vector<int> v, buf1, buf2;

  while(cin >> n >> r, n || r){
    v.clear();
    for(int i=1; i<=n; i++){
      v.push_back(i);
    }

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

      buf1.clear();  buf2.clear();
      for(int j=0; j<v.size(); j++){
        if(j < n-p-(c-1) || n-p < j){
          buf1.push_back(v[j]);
        } else {
          buf2.push_back(v[j]);
        }
      }

      v.clear();
      for(int j=0; j<buf1.size(); j++){
        v.push_back(buf1[j]);
      }
      for(int j=0; j<buf2.size(); j++){
        v.push_back(buf2[j]);
      }
    }

    cout << v[v.size()-1] << endl;
  }

  return 0;
}