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>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
const double PI=acos(-1.0);
//---------------------------------------------------------------------------//
int n,r,p1,c;
int huda[51],huda2[51];
int main(){
        while(1) {
                cin>>n>>r;
                if(n==0 && r==0) {
                        return 0;
                }
                for(int i=0; i<r; i++) {
                        cin>>p1>>c;
                        p1--;
                        for(int j=0; j<n; j++) {
                                huda[i]=n-i;
                                huda2[i]=huda[i];
                        }
                        for(int j=0; j<c; j++) {
                                huda2[j]=huda2[j+p1];
                        }
                        for(int j=0; j<p1; j++) {
                                huda2[j+c]=huda[j];
                        }
                        for(int j=0; j<n; j++) {
                                huda[j]=huda2[j];
                        }
                }
                cout<<huda[0]<<endl;
        }
}

C++: #include<bits/stdc++.h>
using namespace std;

int main() {

  while(1) {
    int n, r;
    cin>>n>>r;
    if(n==0) break;
    int p, c;
    int a[n];
    for(int i = 1; i <= n; i++) {
      a[i-1] = n - i + 1;
    }
    for(int i = 0; i < r; i++) {
      cin>>p>>c;
      rotate(a, a+p-1, a+p+c-1);
	}
    cout<<a[0]<<endl;
  }

  return 0;
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, r;
	VI ps, cs, cards, temp;
	while(1){
		ps.clear();
		cs.clear();
		cards.clear();
		cin >> n >> r;
		if(n == 0 && r == 0) break;
		rep(i, n){
			cards.pb(i + 1);
		}
		reverse(all(cards));
		rep(i, r){
			int p, c;
			cin >> p >> c;
			ps.pb(p);
			cs.pb(c);
		}
		rep(i, r){
			temp.clear();
			REP(j, ps[i] - 1, ps[i] + cs[i] - 1){
				temp.pb(cards[j]);
			}
			rep(j, ps[i] - 1){
				temp.pb(cards[j]);
			}
			REP(j, ps[i] + cs[i] - 1, cards.size()){
				temp.pb(cards[j]);
			}
			cards.clear();
			cards = temp;
		}
		cout << cards[0] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <array>

using namespace std;

int main(){
    int A[51];
    int n,m,p,c;
    while(true){
        cin >> n >> m;
        if(n+m == 0)break;
        for(int i = 0;i < n;i++)A[i] = n - i;
        for(int i = 0;i < m;i++){
            cin >> p >> c;
            rotate(A,A+p-1,A+p+c-1);
//            for(int k = 0;k < n;k++){
//                cout << A[k] << " ";
//            }
//            cout << endl;
        }
        cout << A[0] << endl;
    }
}

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

#define INF 1000000007LL
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)

int n,r,p[55],c[55];

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

C++: #include <bits/stdc++.h>

using namespace std;
#define all(a)a.begin(),a.end()
const int INF = 1<<30;
const int mod= int(1e9)+7;

int main(){
    while(1){
       int n,r;cin >>n>>r;
       if(n==0&&r==0)break;
       vector<int>card(n);
        for (int i = 0; i < n; ++i) {
            card[i]=n-i;
        }
//        for (int j = 0; j < n; ++j) {
//            cout <<card[j]<<" ";
//        }cout <<endl;
        for (int i = 0; i < r; ++i) {
            int p,c;cin >>p>>c;
            vector<int>b;
            for (int j =0; j <c; ++j) {
                b.push_back(card[j+p-1]);
            }
            for (int j = p-2; j>=0; --j) {
                card[j+c]=card[j];
            }
//            for (int j = 0; j < n; ++j) {
//                  cout <<card[j]<<" ";
//            }cout <<endl;
            for (int j = 0; j < c; ++j) {
                card[j]=b[j];
            }
//            for (int j = 0; j < n; ++j) {
//                cout <<card[j]<<" ";
//            }
//            cout <<endl;
        }
        cout <<card[0]<<endl;
    }
}

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

#define TEST 0 //??\??????????????????(1:??????????????\??? 0:?¨??????\???)
#if TEST
FILE *in = freopen("./Q/A", "r", stdin);
FILE *out = freopen("./A/A", "w", stdout);
#endif

int card[2][50];

int calIndex(int i, int p, int c){
    if(i < c){
        return p+i-1;
    } else if(i < p+c-1){
        return i-c;
    } else {
        return i;
    }
}

void setCard(int n, int turn, int p, int c){
    for(int i = 0; i < n; i++){
        card[turn][i] = card[(turn+1)&1][calIndex(i,p,c)];
    }
}

int main(int argc, const char * argv[]) {
    while(1){
        int n, r; cin >> n >> r;
        if(!n && !r) break;
        
        for(int i = 0; i < n; i++){
            card[1][i] = n-i;
        }
        
        for(int i = 0; i < r; i++){
            int turn = i & 1;
            
            int p, c; cin >> p >> c;
            setCard(n, turn, p, c);
            
        }
        cout << card[(r+1)&1][0] << endl;
        
    }
    
    
#if TEST
    fclose(in);
    fclose(out);
#endif
}