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;

int main() {
        int i, j;
        int n, r;
        while (cin >> n >> r) {
                if (n == 0 && r == 0) break;
                vector<int> a(n);
                vector<bool> ok(n);
                for (i = 0; i < n; i ++) {
                        a[i] = i + 1;
                        ok[i] = true;
                }
                for (i = 0; i < r; i ++) {
                        int p, c;
                        cin >> p >> c;
                        int cnt = 0;
                        int pp = a.size() - 1;
                        while (cnt < p - 1) {
                                if (ok[pp]) cnt ++;
                                pp --;
                        }
                        cnt = 0;
                        vector<int> tmp;
                        vector<bool> tmpok;
                        while (cnt < c) {
                                if (ok[pp]) {
                                        cnt ++;
                                        ok[pp] = false;
                                        tmp.push_back(a[pp]);
                                        tmpok.push_back(true);
                                }
                                pp --;
                        }
                        for (j = tmp.size() - 1; j >= 0; j --) a.push_back(tmp[j]);
                        for (j = tmpok.size() - 1; j >= 0; j --) ok.push_back(tmpok[j]);
                        //cout << "================" << endl;
                        //for (j = 0; j < a.size(); j ++) {
                        //        cout << a[j] << ' ' << endl;
                        //}
                }
                cout << a.back() << endl;
        }
        return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <stack>

using namespace std;

int main(){
  int n ,r;
  while (cin >> n >> r){
    if (n == 0 && r == 0){
      return 0;
    }
    stack<int> cards;

    for (int i=0; i<n; ++i){
      cards.push(i+1);
    }
    
    for (int i=0; i<r; ++i){
      int p, c;
      cin >> p >> c;//上からP枚目からC枚とってシャッフル
      int *tmp1 = new int[p-1];
      for (int i=(p-2); 0<=i; --i){
	tmp1[i] = cards.top();
	cards.pop();
      }
      int *tmp2 = new int[c];
      for (int i=(c-1); 0<=i; --i){
	tmp2[i] = cards.top();
	cards.pop();
      }
      for (int i=0; i<(p-1); ++i){
	cards.push(tmp1[i]);
      }
      for (int i=0; i<c; ++i){
	cards.push(tmp2[i]);
      }
      delete[] tmp1;
      delete[] tmp2;      
    }
    cout << cards.top() << endl;
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

int input() {
	int input[51][2];
	cin >> input[0][0] >> input[0][1];								
	if (input[0][0] == 0 && input[0][1] == 0) {
		return 0;
	}
	for (char pos = 1; pos <= input[0][1]; pos++) {
		cin >> input[pos][0] >> input[pos][1];
	}																

	int whtop = 1;													
	whtop = input[input[0][1]][0];
	input[0][1]--;
	while (input[0][1] != 0) {

		if (input[input[0][1]][1] >= whtop) {
			whtop = input[input[0][1]][0] + whtop - 1;
		}
		else {
			whtop = whtop - input[input[0][1]][1];
		}
		input[0][1]--;
	}
	return input[0][0]-whtop+1;
}




int main()
{
	int output[1000];
	char topos = 0;
	while (1) {
		int check;
		check=input();
		if (check == 0)break;
		else {
			output[topos] = check;
			topos++;
		}
	}

	char sendpos = 0;
	while (sendpos < topos) {
		cout << output[sendpos] << endl;
		sendpos++;
	}


}

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

int hanafuda[50], tmp[50];

int main()
{
    int n,c,p,r;
    while(cin >> n >> r && n && r) {
        for(int i = 0; i < n; i++)
            hanafuda[i] = n - i;
        

        for(int i = 0; i < r; i++) {
            cin >> p >> c;
            for(int i = 0; i < n; i++) 
                tmp[i] = hanafuda[i];

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

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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double EPS = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int n, r;
int p, c;

int main() {
	while (cin >> n >> r, n && r) {
		if (n == 1) {
			cout << 1 << endl;
			continue;
		}

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

		rep(i, r) {
			cin >> p >> c;
			vector<int> tmp;
			rep(j, c) tmp.push_back(card[p - 1 + j]);
			rep(j, p - 1) tmp.push_back(card[j]);
			REP(j, p + c, n) tmp.push_back(card[j]);
			card = tmp;
		}
		cout << card[0] << endl;
	}
}

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

int main(){
	int n,r;
	while(scanf("%d%d",&n,&r),n){
		deque< int > DQ;
		for(int i = 0; i < n; i++){
			DQ.push_back(n-i);
		}
		for(int i = 0; i < r; i++){
			int p,c;
			scanf("%d%d",&p,&c);
			p--;c--;
			deque < int > :: iterator it;
			vector < int > sub;
			int cnt = 0;
			for(it = DQ.begin(); it != DQ.end(); it++){
				if(cnt >= p && cnt <= c+p){
					sub.push_back(DQ[cnt]);
					DQ.erase(it,it);
				}
				cnt++;
			}
			for(int j = 0; j < sub.size(); j++){
				DQ.push_front(sub[sub.size()-j-1]);
			}
		}
		printf("%d\n",DQ[0]);
	}
	return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  int n, r;
  while(1) {
    cin >> n >> r;
    if(n==0 && r==0) break;
    int num[n+1];
    FOR(i,0,n+1) num[i] = i;
    while(r--) {
      int p, c;
      scanf("%d %d\n", &p, &c);
      int tmp[c+p-1];
      FOR(i,0,c) {
        tmp[i] = num[n-(p-1)-i];
      }
      FOR(i,c,c+p-1) {
        tmp[i] = num[n-(i-c)];
      }
      FOR(i,0,c+p-1) num[n-i] = tmp[i];
    }
    printf("%d\n", num[n]);
  }
  return 0;
}