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>
#include<vector>

using namespace std;

vector<int> Deck;

void shuffle(int p, int c) {
  vector<int> tmp = Deck;
  for(int i=0; i<Deck.size(); i++) {
    if(i<=c) {
      Deck[i] = tmp[p+i-1]; // -1不要?
    }
    else if(i) {
      Deck[i] = tmp[i-c];
    }
  }
}

int main() {
  int n, r;

  while(cin>>n>>r && n>0) {
    Deck.clear();
    for(int i=0; i<n; i++) {
      Deck.push_back(n-i);
    }
    for(int i=0; i<r; i++) {
      int p, c;
      cin>>p>>c;
      shuffle(p, c);
    }
    cout<<Deck[0]<<endl;
  }
}

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

using namespace std;

int main(void) {
	int n,r;
	while (cin >> n >> r, n) {
		list<int> hana;
		for (int i = 0; i < n; ++i) {
			hana.push_back(i+1);
		}
		
		int p,c,count;
		for (int i = 0; i < r; ++i) {
			cin >> p >> c;
			count = 1;
			for (list<int>::iterator itr = hana.begin(); itr != hana.end();) {
				if (count > n-(p-1)-c && count < n-(p-2)) {
					hana.push_back(*itr);
					itr = hana.erase(itr);
				}
				else {
					++itr;
				}
				++count;
			}
		}
		count = 1;
		for (list<int>::iterator itr = hana.begin(); itr != hana.end(); ++itr) {
			if (count == n) {
				cout << *itr << endl;
			}
			++count;
		}
	}

	return 0;
}

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

using namespace std;

int input() {
	int input[51][2];
	cin >> input[0][0] >> input[0][1];								//まずnとr
	if (input[0][0] == 0 && input[0][1] == 0) {
		return 0;
	}
	for (char pos = 1; pos <= input[0][1]; pos++) {					//r回のシャッフルの仕方を入力
		cin >> input[pos][0] >> input[pos][1];
	}																//ここまで入力

	/*シャッフルもどし*/
	int whtop = 1;													//最後一番上にいるカードは、今何番目にいる？
	if (input[0][1]==0){											//一回もシャッフルしないならコレ
		return input[0][0];
	}
	else {
		whtop = input[input[0][1]][0];								//一回目のもどしだけ別枠
		input[0][1]--;
		while (input[0][1] != 0) {	
			if (input[input[0][1]][1] < whtop && input[input[0][1]][0] >= whtop) {
				whtop = whtop - input[input[0][1]][1];
			}
			else whtop = input[input[0][1]][0] + whtop - 1;			//input[input[0][1]][1] >= whtop
			input[0][1]--;
		}

		return input[0][0] - whtop + 1;
	}
}


int main()
{
	while (1) {
		int check;
		check = input();
		if (check == 0)break;
		else {
			cout << check << endl;
		}
	}
}

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

int main() {
	int n, r, p, c;
	vector<int> v, vs;
	while(1) {
		cin >> n >> r;
		if(!n&&!r) break;
		v.clear();
		for(int i=n; i>0; --i) v.push_back(i); 
		for(int i=0; i<r; ++i) {
			cin >> p >> c;
			vs.clear();
			for(int j=p-1; j<p-1+c; ++j) vs.push_back(v[j]);
			v.erase(v.begin()+p-1, v.begin()+p-1+c);
			v.insert(v.begin(), vs.begin(), vs.end());
		}
		cout << v[0] << endl;
	}
	return 0;
}

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

int main() {
    int n, r, p, c;
    while (cin >> n >> r, n | r) {
        vector<int> deck;
        for (int i = n; i > 0; i--) deck.push_back(i);
        while (r--) {
            cin >> p >> c;
            rotate(deck.begin(), deck.begin() + p - 1, deck.begin() + p - 1 + c);
        }
        cout << deck[0] << endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main(void){
	
	int card[50],temp[50],yamafuda,cut,p,c;
	
	while(cin>>yamafuda>>cut,yamafuda){
		
		for(int i=0;i<50;i++){
			card[i]=0;
			temp[i]=0;
		}
		for(int i=1;i<=yamafuda;i++){
			card[i]=yamafuda-i;
		}
		for(int i=0;i<cut;i++){
			cin>>p>>c;
			for(int j=0;j<p-1;j++){				
				temp[j]=card[j];
			}
			for(int j=0;j<c;j++){
				card[j]=card[j+(p-1)];
			}
			for(int j=0;j<p-1;j++){
				card[j+c]=temp[j];
			}
		}
		cout<<card[0]<<endl;
	}

}

C++: #define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

int main() {
	while (1) {
		ll n, r;
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		ll a[55], b[55];
		repi(i, 1, n + 1) a[n - i] = b[n - i] = i;
		repi(i, 0, r) {
			ll p, c;
			cin >> p >> c;
			repi(j, 0, p - 1) b[c + j] = a[j];
			repi(j, 0, c) b[j] = a[p - 1 + j];
			repi(j, 0, n) a[j] = b[j];
		}
		wrln(a[0]);
	}
	return 0;
}

C++: //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1129&lang=jp

#include <iostream>
#include <algorithm>
using namespace std;
int n,r,p,c;

int main(){
  while (cin >> n >> r && n){
    int A[n];
    for (int i=0; i<n; i++){
      A[i] = n-i;
    }
    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 <iostream>
#include <vector>

using namespace std;

vector<int> cut(vector<int>& card, int ft, int noc)
{
	vector<int>::iterator itr;
	for(int i = 0; i < noc; i++){
		itr = card.end() - ft - (noc - 1);
		card.push_back(*itr);
		card.erase(itr);
	}
	return card;
}

int main(void)
{
	int num, cut_num;
	vector<int>::iterator itr;

	while(1){
		cin >> num >> cut_num;
		if(num == 0 && cut_num == 0){
			break;
		}

		vector<int> card;
		for(int i = 0; i < num; i++){
			card.push_back(i + 1);
		}

		for(int i = 0; i < cut_num; i++){
			int from_top, num_of_cards;
			cin >> from_top >> num_of_cards;
			card = cut(card, from_top, num_of_cards);
		}
		itr = card.end();
		cout << *itr << endl;
		//for(itr = card.end() - 1; itr  >= card.begin(); itr--)
			//cout << *itr << endl;
		//cout << endl;

	}
	return 0;
}