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 <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

bool debug=false;
/*---------------------------------------------------*/

int n,r,p,c;
int card[55];

void init(int n){
  rep(i,n)card[i]=n-i;
}

void shuffle(){
  int tmp[55];
  rep(i,r){
    cin>>p>>c;
    rep(i,c)tmp[i]=card[p+i-1];
    if(debug){cout<<"tmp ";rep(i,c)cout<<tmp[i]<<" ";cout<<endl;}
    for(int i=p-2;i>=0;i--)card[i+c]=card[i];
    rep(i,c)card[i]=tmp[i];
    if(debug){rep(i,n)cout<<card[i]<<" ";cout<<endl;}
  }
}

int main(){

  while(cin>>n>>r){
    if(n==0&&r==0)break;
    init(n);
    shuffle();
    cout<<card[0]<<endl;
  }
  
  return 0;
}

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

int main(){
	
	int n,r;
	while(cin>>n>>r){
		if(n!=r!=0){
		int h[55]={0},m[55]={0};
		int p,d;
		for(int i=0;i<n;i++)
			h[i]=n-i;
		while(r>0){
			cin>>p>>d;
			int j=d-1;
			for(int i=p+d-1;i>=p;i--)
				m[j--]=h[i-1];
			for(int i=p-1;i>0;i--)
				h[i+d-1]=h[i-1];
			for(int i=d;i>0;i--)
				h[i-1]=m[i-1];
			r--;
	}
			cout<<h[0]<<endl;
	}
	else
		break;
	}
	
}

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

#define MAX_N 100

using namespace std;

int main(int argc, char const *argv[])
{
	int n,r;
	int p,c;
	int h[MAX_N];

	while(1){

		cin>>n>>r;
		if (n+r==0){
			break;
		}

		for(int i1=0;i1<n;i1++){
			h[i1]=n-i1;
		}

		for(int i1=0;i1<r;i1++){
			cin>>p>>c;
			queue<int> q1;
			queue<int> q2;

			for(int i2=0;i2<p-1;i2++){
				q1.push(h[i2]);
			}
			for(int i2=0;i2<c;i2++){
				q2.push(h[i2+p-1]);
			}
			for(int i2=0;i2<p-1+c;i2++){
				if(i2<c) {
					h[i2]=q2.front();
					q2.pop();
				}
				else {
					h[i2]=q1.front();
					q1.pop();
				}
			}
		}
		cout<<h[0]<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int main(void){
while(1){
int n,r;
cin>>n>>r;
if(n==0)break;
vector<int> a(n);
for(int i=0;i<n;i++)a[i]=n-i;
for(int i=0;i<r;i++){
int p,c;
cin>>p>>c;
vector<int> temp(p+c-1);
for(int j=0;j<c;j++)temp[j]=a[p+j-1];
for(int j=c;j<c+p-1;j++)temp[j]=a[j-c];
for(int j=0;j<c+p-1;j++)a[j]=temp[j];
//for(int j=0;j<n;j++)cout<<a[j]<<endl;
	}	
cout<<a[0]<<endl;
}
return 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;
}