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 <cstdio>
#include <stack>
using namespace std;
int main(int argc, char *argv[]) {
	while (true) {
		int N,R;
		scanf("%d %d",&N, &R);
		if (N == 0 && R == 0) break;
		stack<int> deck;
		for (int i=0;i<N;i++) deck.push(i+1);
		for (int i = 0; i < R; i++) {
			int P,C;
			scanf("%d %d",&P,&C);
			stack<int> ps,cs;
			if (P == 1) continue;
			for (int j = 0; j < P-1; j++) {
				ps.push(deck.top());
				deck.pop();
			}
			for (int j = 0; j < C; j++) {
				cs.push(deck.top());
				deck.pop();
			}
			while (ps.size()>0) {
				deck.push(ps.top());
				ps.pop();
			}
			while (cs.size()>0) {
				deck.push(cs.top());
				cs.pop();
			}
		}
		printf("%d\n",deck.top());
	}
	return 0;
}

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

void Shuffle(int n, int r){
	int c,p;
	int Deck[50];
	int tmp[50];
	//?±±?????????
	for(int i = 0;i < n;i++){
		Deck[i] = n - i;
	}
	//?????£?????????
	for(int i = 0; i < r; i++){
		cin >> p >> c;
		p--; //??????????????????????????????

		//p??????c???????????????????????£??????
		for(int j = 0; j < c; j++){
			tmp[j] = Deck[j + p];
		}
		//???????????????
		for(int j = p-1; j >= 0; j--){
			Deck[j+c] = Deck[j];
		}
		//?????£?????????????????????????????????
		for(int j = 0; j < c; j++){
			Deck[j] = tmp[j];
		}
	}
	cout << Deck[0] << endl;
}

int main(void){
	int n; //?±±???????????°
	int r; //???????????????????????°
	while(1){
		cin >> n >> r;
		if(n == 0 && r == 0){
			exit(1);
		}
		Shuffle(n,r);
	}
	return 0;
}

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

using namespace std;

int main()
{
	int n, r;

	while (scanf("%d %d", &n, &r), n){
		vector<int> v;

		for (int i = 0; i < n; i++){
			v.push_back(n - i);
		}

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

			scanf("%d %d", &p, &c);

			stack<int> s;

			for (int j = p - 1; j < p + c - 1; j++){
				s.push(v[j]);
				v[j] = 0;
			}

			for (int j = n - 1; j >= c; j--){
				if (v[j] == 0){
					v[j] ^= v[j - c];
					v[j - c] ^= v[j];
					v[j] ^= v[j - c];
				}
			}

			for (int j = c - 1; j >= 0; j--){
				v[j] = s.top();
				s.pop();
			}
		}

		printf("%d\n", v[0]);
	}

	return (0);
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	int n,m,a,b;
	while(cin>>n>>m,n){
		int d[n],p[n],cnt=0;
		for(int i=n;i>0;i--){
			d[cnt]=i;
			p[cnt]=0;
			cnt++;
		}
		for(int i=0;i<m;i++){
			cin>>a>>b;
			for(int j=0;j<a-1;j++)
			p[j]=d[j];
			for(int j=0;j<b;j++)
			d[j]=d[a-1+j];
			for(int j=0;j<a-1;j++)
			d[b+j]=p[j];
		}
		cout<<d[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], cards.size()){
				temp.pb(cards[j]);
			}
			cards.clear();
			cards = temp;
		}
		cout << cards[0] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)

int main(){
    int n,r,p,c;
    int a[52]={},tmp[52]={};
    while(cin>>n>>r,n|r){
        rep(i,n)a[i+1]=n-i;
        while(r--){
            cin>>p>>c;
            rep(i,c)tmp[i+1]=a[p+i];
            rep1(i,p-1)tmp[c+i]=a[i];
            rep1(i,c+p-1)a[i]=tmp[i];
        }
        cout<<a[1]<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m;
    while (true) {
        cin >> n >> m;
        if (!n && !m) break;
        int p, c;
        vector<int> a(n);
        vector<int> b;
        for (int i = 0; i < n; ++i) {
            a[i] = n-i;
        }
        for (int i = 0; i < m; ++i) {
            cin >> p >> c;
            for (int j = p-1; j < p+c-1; ++j) {
                b.push_back(a[j]);
            }
            for (int j = 0; j < p; ++j) {
                b.push_back(a[j]);
            }
            for (int j = p+c; j < n; ++j) {
                b.push_back(a[j]);
            }
            a = b;
            b.clear();
        }
        cout << a[0] << endl;
    }
}

C++: #include <iostream>

using namespace std;

int cut(int n, int r, int p, int c, int s[60]){
	int temp[60] = {0};

	for(int i = 0;i < r;i++){
		for(int j = 0;j <= n;j++){
			temp[j] = s[j];
		}
		for(int j = 0;j < p;j++){
			s[n - p - c + j + 2] = temp[n - p + j + 2];
		}
		for(int j = 0;j < c;j++){
			s[n - c + 1 + j] = temp[n - p - c + j + 2];
		}
	}

	return s[n];
}

int main(){
	int n, r, p, c, s[60];
	while(1){
		cin >> n >> r;
		if(n == 0 && r == 0) break;

		for(int i = 0;i <= n;i++){
			s[i] = i;
		}
		cin >> p >> c;

		if(n + 1 < p + c) continue;

		int ans = cut(n, r, p, c, s);

		cout << ans << endl;
	}

	return 0;
}

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

void shuffleCards( int* a, int n, int p, int c )
{
    int copy1[p], copy2[c];
    for( int i = 1; i < p; i++ )
        copy1[i] = a[n+1-i];

    for( int i = p; i < p + c; i++ )
        copy2[i-p] = a[n+1-i];

    for( int i = 1; i <= c; i++ )
        a[n+1-i] = copy2[i-1];

    for( int i = 1; i < p; i++ )
        a[n+1-c-i] = copy1[i];
    
}

int main()
{
    int n, r, a[51], p, c;

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

        for( int i = 1; i <= 50; i++ )
            a[i] = i;

        cin >> r;

        for( int i = 0; i < r; i++ )
        {
            cin >> p >> c;
            shuffleCards( a, n, p, c );
        }
        cout << a[n] << endl;
    }
    return 0;
}