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 <bits/stdc++.h>

#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;


void shuffle(int p, int c, int A[]) {
    rotate(A, A+p-1, A+p+c-1);
}

int main()
{   
    int n, r;
    while (cin >> n >> r && n > 0) {

        int p, c;
        int A[n];

        /* 山札を作成 */

        for (int i = 0; i < n; i++) 
            A[i] = i+1;
            
        reverse(A, A+n);

        /* シャッフルする */

        for (int i = 0; i < r; i++) {
            cin >> p >> c;
            shuffle(p, c, A);
        }

        /* 山札の一番上を表示 */
        
        cout << A[0] << endl;
    }
}

C++: 
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)

int main(){
  int n, r;
  while(cin >>n >>r && n){
    vector<int> v;
    for(int i = n; i > 0; i--) v.push_back(i);

    REP(j, r){
      int p, c;
      cin >>p >>c;
      vector<int> next;
      for(int i = 0; i < c; i++) next.push_back(v[p - 1 + i]);
      for(int i = 0; i < p - 1; i++) next.push_back(v[i]);
      for(int i = p + c - 1; i < v.size(); i++) next.push_back(v[i]);
      v = next;
    }
    cout <<v[0] <<endl;
  }
  return 0;
}

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

int main(){
	int n,r;
	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<iostream>
#include<vector>
using namespace std;

int main(){
	int n,r;
	while(cin >> n >> r){
		if(n==0 && r==0) break;
		int card[51];
		bool flag[51];
		for(int i=0; i<n; i++){
			card[i] = n-i;
			flag[i]=false;
		}
		for(int j=0; j<r; j++){
			int p,c;
			cin >> p >> c;
			vector<int> change;
			for(int i=p-1; i<p-1+c; i++){
				change.push_back(card[i]);
				flag[card[i]]=true;
			}
			for(int i=0; i<p-1; i++){
				change.push_back(card[i]);
				flag[card[i]]=true;
			}
			for(int i=p-1+c; i<n; i++){
				change.push_back(card[i]);
			}
			int count=0;
			vector<int>::iterator it = change.begin();
			while(it!=change.end()){
				card[count] = *it;
				count++;
				it++;
			}
			for(int i=0; i<n; i++) cout << card[i] << " ";
			cout << endl;
		}
		cout << card[0] << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
	int n, r;

	while (cin >> n >> r && (n > 0 && r > 0)) {
		int card[51];

		for (int i = 1; i <= n; i++) {
			card[i] = n - i + 1;
		}

		int p, c;
		for (int i = 0; i < r; i++) {
			cin >> p >> c;

			int temp[50];
			for (int j = 0; j < c; j++) {
				temp[j] = card[p + j];
			}

			for (int j = p - 1; j >= 1; j--) {
				card[j + c] = card[j];
			}

			for (int j = 0; j < c; j++) {
				card[j + 1] = temp[j];
			}
		}

		cout << card[1] << endl;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

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

		int *a;
		a = new int[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;
			int *data1,*data2;
			data1 = new int[p];
			data2 = new int[c];

			for(int i=0;i<p-1;i++){
				data1[i]=a[i];
			}
			for(int i=0;i<c;i++){
				data2[i]=a[i+p-1];
			}
			for(int i=0;i<c;i++){
				a[i]=data2[i];
			}
			for(int i=0;i<p-1;i++){
				a[i+c]=data1[i];
			}
		}

		cout<<a[0]<<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
    int n,r,p,c;
    int card[100],temp[100];
    
    while(cin >> n >> r,n!=0&&r!=0){
        for(int i=0;i<n;i++) card[i] = n-i;
        for(int i=0;i<r;i++){
            cin >> p >> c;
            for(int i=0;i<c;i++) temp[i] = card[p-1+i];
            for(int i=0;i<p-1;i++) temp[i+c] = card[i];
            for(int i=0;i<p+c-1;i++) card[i] = temp[i];
        }
        cout << card[0] << endl;
    }

    return(0);
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main()
{
    int n, r;
    while (cin >> n >> r, n|r) {
        vi v[2];
        rep(i, n){
            v[0].pb(n-i);
            v[1].pb(n-1);
        }
        rep(i, r) {
            int p, c;
            cin >> p >> c;
            int j = 0;
            for (; j < c; j++){
                v[(~i)&1][j] = v[i&1][j+p-1];
            }
            for (; j < c + p-1; j++){
                v[(~i)&1][j] = v[i&1][j-c];
            }
            for (; j < n; j++){
                v[(~i)&1][j] = v[i&1][j];
            }
        }
        cout << v[r&1][0] << endl;
    }
    return 0;
}

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

int main(){
    int N,r;
    vector<int> ans;
    while(cin>>N>>r,N != 0 && r != 0){

        stack<int> card;
        for(int i = 1;i <= N;i++) card.push(i);

        for(int i=0;i<r;i++){
            int P,C;
            stack<int> p;
            stack<int> c;
            cin>>P>>C;
            
            for(int i=0;i<P-1;i++){
                p.push(card.top());
                card.pop();
            }

            for(int i=0;i<C;i++){
                c.push(card.top());
                card.pop();
            }

            while(!p.empty()){
                card.push(p.top());
                p.pop();
            }

            while(!c.empty()){
                card.push(c.top());
                c.pop();
            }
            
        }
        ans.push_back(card.top());
    }
    for(int i : ans) cout<<i<<endl;
}