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++: // Author :
// Date :
// Problem:
// Solution:
// Comment:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstring>

#define pp push
#define pb push_back
#define mp make_pair
#define xx first
#define yy second

using namespace std;

queue <int> deck,temp,tempp;

void shuffle(int x,int c){
    while(x--){
        temp.pp(deck.front());
        deck.pop();
    }
    while(c--){
        tempp.pp(deck.front());
        deck.pop();
    }
    while(temp.size()){
        tempp.pp(temp.front());
        temp.pop();
    }
    while(deck.size()){
        tempp.pp(deck.front());
        deck.pop();
    }
    while(tempp.size()){
        deck.pp(tempp.front());
        tempp.pop();
    }
}

void init(int n){
    while(deck.size()) deck.pop();
    
    for(int i = n ; i >= 1 ; i--) deck.pp(i);
}
main(){
    int n,r;
    int a,b;
    
    while(cin >> n >> r){
        if(n == 0) break;
    
        init(n);
        
        while(r--){
            cin >> a >> b;
            shuffle(a-1,b);
        }
        
        cout << deck.front() << endl;
    }
    #ifdef GEREL
        for(;;);
    #endif

    return 0;
}

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

vector<int> v;

int main(){
while(1){//start	
	int n, r;
	cin >> n >> r;
	if(n == 0 and r == 0) break;
	
	for(int i = 1; i <= n; i++) v.push_back(i);
	reverse(v.begin(), v.end());

	for(int i = 0; i < r; i++){
		stack<int> st;
		int p, c;
		cin >> p >> c;
		for(int j = 0; j < c; j++){
			st.push(v[p + j - 1]);
			//cout << "que = " << v[p + j - 1] << endl;
		}
		v.erase(v.begin() + p - 1, v.begin() + p + c - 1);
		//for(int k = 0; k < (int)v.size(); k++) cout << v[k] << endl;
		

		reverse(v.begin(), v.end());
		while(st.size()){
			int tmp = st.top();
			//cout << "tmp = " << tmp;
			st.pop();
			v.push_back(tmp);
		}
		reverse(v.begin(), v.end());

		//debug
		//cout << endl;
		//for(int k = 0; k < (int)v.size(); k++) cout << v[k] << endl;
		//cout << endl;
	}

	cout << v[0] << endl;
	v.clear();
}//end
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int main(){
  int n,r;
  while(1){
    cin>>n>>r;
    if(n==0&&r==0)break;
    int d[51];
    //?????????
    for(int i=0;i<n;i++){
      d[i]=n-i;
    }

    if(debug)for(int i=0;i<n;i++)cout<<d[i]<<" ";
    if(debug)cout<<endl;
      
    for(int i=0;i<r;i++){
      int p,c,tmp[51];
      cin>>p>>c;
      
      for(int j=0;j<c;j++)tmp[j]=d[j+p-1];

      for(int j=p-2;j>=0;j--)d[j+c]=d[j];

      for(int j=0;j<c;j++)d[j]=tmp[j];

      
      if(debug)for(int i=0;i<n;i++)cout<<d[i]<<" ";
      if(debug)cout<<endl;
    }
    cout<<d[0]<<endl;
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <cstring>

using namespace std;
const int INF = (1<<30);
typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for (int i = 0; i < a; i++)

int sx, sy;

int gx, gy;

int qqq;

//各座標までの最短距離
int d[100][100];


//移動方向のベクトル
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

//汎用
ll ans = 0;
pair<int, int> red[101], blue[101];
ll BIG = 10000000000;

//累乗
ll POW(ll a, ll b) {
ll c = 1;
for (int i = 0; i < b; ++i) {
c *= a;
}
return c;
}

//階乗
int Kaijou(int a) {
if (a < 2) return 1;
return a * Kaijou(a - 1);
}


int A[200000];
int kinds[200001];


int main() 
{
	int n,r;
	while(1){
		cin >> n>> r;
		if (n == 0&&r==0) break;

		vector<int> s(n);
		std::iota(s.begin(), s.end(), 1);
		reverse(s.begin(), s.end());

		rep(i, r) {
			int p, c;
			cin >> p >> c;
			int toU[100] = { 0 }, toD[100] = { 0 };
			rep(i, c) {
				toU[i] = s[p - 1 + i];
			}
			rep(i, p - 1) {
				toD[i] = s[i];
			}
			rep(i, c) {
				s[i] = toU[i];
			}
			rep(i, p - 1) {
				s[i + c] = toD[i];
			}
		}
	
		cout << s[0] << endl;
	}
	cin >> qqq;
}

C++: #include <iostream>
using namespace std;
int card[50];
int buffer[50];
int main()
{
	int n,r;
	while(cin>>n>>r,n!=0){
		for(int i=0;i<n;i++)card[i]=i+1;
		for(int i=0;i<r;i++){
			int p,c;
			cin>>p>>c;
			for(int j=0;j<p-1;j++)
				buffer[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]=buffer[j];
		}
		cout<<card[0]<<endl;
	}
	return 0;
}

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

int main(){
	int n,r;
	int c= 0;
	while((cin >> n)&&(cin >> r)&&(n!=0)&&(r!=0)){
		int a[n];
		int cnt=n;
		for(int i=0;i<n;i++){
			a[i] = cnt;
			cnt--;
			//cout << "a[" << i << "]" << a[i] << endl;
		}
		int p,c;
		//cout << endl;
		for(int i=0;i<r;i++){
			cin >> p;
			cin >> c;
			int b[p+c];
			//cout << p << endl;
			//cout << c << endl;
			//cout << endl;
			if(n!=c){
				for(int j=0;j<p;j++){
					b[j+c] = a[j];
				}
				for(int j=0;j<c;j++){
					b[j] = a[p+j-1];	
				}
				for(int j=0;j<p+c;j++){
					a[j] = b[j];	
					//cout << "a[" << j << "]" << a[j] << endl;
				//	cout << "b[" << j << "]" << b[j] << endl;
				}
			}
		}
		cout << a[0] << endl;
	}
}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;


int main(void) {
	
	while (1) {
		int n, r;
		int p, c;
		int a[51] = {};
		int b[51] = {};
		
		cin >> n >> r;
		if (n == 0 && r == 0) {
			break;
		}
		FOR(i, 1, n) {
			a[i] = n - i + 1;
		}
		FOR(i, 1, r) {
			cin >> p >> c;
			FOR(t, 1, p - 1) {
				b[t] = a[t];
			}
			FOR(t, 1, c) {
				a[t] = a[p + t - 1];
			}
			FOR(t, 1, p - 1) {
				a[p + t - 1] = b[t];
			}
		}
		cout << a[1] << endl;
	}

}

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

using namespace std;

int main(void){
	int p,c;

	for(int n,r;cin >> n >> r,n||r;){
		string card;

		for(int i=0;i<n;i++)
			card+=(n-i+0x30);

		for(int i=0;i<r;i++){
			cin >> p >> c;
			card = card.substr(p-1,c)+card.substr(0,p-1)+card.substr(p+c-1);
		}

		cout << (int)card[0]-0x30 << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

int main(){
	
	int n, r, p, c;
	
	vector<int> v1, v2;
	
	while(true){
		cin >> n >> r;
		if(n == 0 && r == 0){
			break;
		}
		for(int i = 1; i <= n; i++){
			v1.push_back(i);
		}
		for(int loop = 0; loop < r; loop++){
			cin >> p >> c;
			p--;
			copy(v1.end() - p - c, v1.end() - p, back_inserter(v2));
			v1.erase(v1.end() - p - c, v1.end() - p);
			copy(v2.begin(), v2.end(), back_inserter(v1));
			v2.erase(v2.begin(), v2.end());
			/*
			for(int i = 0; i < v1.size(); i++){
				printf("%d ", v1.at(i));
			}
			printf("\n");
			*/
		}
		printf("%d\n", v1.back());
		v1.erase(v1.begin(), v1.end());
	}
	
	return 0;
}