Go: package main

import "fmt"

func main() {
	var n, r int
	fmt.Scan(&n, &r)
	for n != 0 || r != 0 {
		arr := make([]int, n)
		for i := range arr {
			arr[i] = len(arr) - i
		}

		for i := 0; i < r; i++ {
			var p, c int
			fmt.Scan(&p, &c)
			mid, top, last := arr[:p-1], arr[p-1:p-1+c], arr[p-1+c:]
			arr = append(append(append([]int{}, top...), mid...), last...)
		}
		fmt.Println(arr[0])
		fmt.Scan(&n, &r)
	}
}

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;
}

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

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define na printf("a");
#define nnn(i) printf("%d", i);
#define mod 1000000007

using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	while (1)
	{
		int n = 0, r = 0; cin >> n >> r;
		if (n == 0 && r == 0) { return 0; }
		int p = 0, c = 0;
		vector<int> bef(n + 5);
		vector<int> aft(n + 5);
		rep(i, n) 
		{
			bef[i] = n - i;
			aft[i] = n - i;
		}
		rep(i, r)
		{
			cin >> p >> c;
			rep(j, p - 1){	aft[c + j] = bef[j];	}
			rep(j, c)	{	aft[j] = bef[p - 1 + j];	}
			bef = aft;
		}
		printf("%d\n", bef[0]);
	}
	return 0;
}