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,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X)  ( (X)*(X) )
#define CUBE(X) ( (X)*(X)*(X) )
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;
 
 
void reader(int &a){scanf("%d",&a);}
void reader(double &a){scanf("%lf",&a);}
void reader(char a[]){scanf("%s",a);}
void reader(ll &a){scanf("%lld",&a);}
void reader(ull &a){scanf("%llu",&a);}
// void reader(string& a){cin >> a;};
template<class T,class U> void reader(T& t,U& u){reader(t); reader(u);}
template<class T,class U,class V> void reader(T& t,U& u,V& v){reader(t); reader(u); reader(v);}
 
void writer(int a,char c) {printf("%d",a); putchar(c);}
void writer(ll a,char c) {printf("%lld",a); putchar(c);}
void writer(double a,char c) {printf("%.20lf",a); putchar(c);}
void writer(char a[]) {printf("%s",a);};
void writer(char a[],char c) {printf("%s",a);putchar(c);};
void writer(char a,char c) {putchar(a); putchar(c);};
template<class T>void writerLn(T t){writer(t,'\n');}
template<class T,class U>void writerLn(T t,U u){writer(t,' ');writer(u,'\n');}
template<class T,class U,class V> void writerLn(T t,U u,V v){writer(t,' ');writer(u,' ');writer(v,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){putchar('\n');return;}rep(i,n-1) writer(x[i],' ');writer(x[n-1],'\n');}
template<class T> void writerVec(vector<T> x){int n=x.size();int i;if(!n){putchar('\n');return;}rep(i,n-1) writer(x[i],' ');writer(x[n-1],'\n');}
 

 
// #define int ll
 
bool test = 1;

//............................
#define MAX 300000
signed main(){
  int i,j,k,l;
  while(1) {
	int n,r;
	cin >> n >> r;
	if(n == 0) break;
	vector<int> now(n);
	rep(i,n) {
	  now[i] = n-1-i;
	}
	rep(i,r) {
	  int p,c;
	  cin >> p >> c;
	  vector<int> next = now;
	  rep(j,c) {
		next[j] = now[p-1+j];
	  }
	  rep(j,p-1) {
		next[c+j] = now[j];
	  }
	  now = next;
	}
	cout << now[0]+1 << endl;
  }
  return 0;
}

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

using namespace std;

void sort(int *x, int *y)
{
	int temp;
	temp = *x;
	*x = *y;
	*y = temp;
}

int main(void)
{
	int n, r;
	while(cin >> n >> r && n!=0 && r != 0)
	{	
		vector<int> A(n);
		for(int i = 0;i < n; i++)
		{
			A[i] = n - i;
		}

		int p, c;

		for(int i = 0; i < r; i++)
		{
			cin >> p >> c;
			vector<int> B(p);
			
			int j = 0;
			for(int i = 0; i < p-1;i++)
				B[i] = A[i];

			for(int i = p-1; i < p+c-1; i++)
				sort(&A[i], &A[i-(p-1)]);

			for(int i = c; i < c+p-1;i++)
				A[i] = B[i-c];
		}
		cout << A[0] << endl;
	}
	return 0;
}

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

int main() {
  // 変数の準備。デッキの余分な50枚はカードを一時的に移して置くための場所
  int deck[100] = {}, num, times, p, c;

  while (cin >> num >> times && num) {  // デッキが0枚だったら終了

    // デッキの準備
    for (int i = 0; i < num; i++) {
      deck[i] = num - i;
    }

    // デッキにシャッフルの操作をtimes回する
    for (int i = 0; i < times; i++) {
      cin >> p >> c;

      // 先頭p-1枚を一時的に退避
      for (int j = 0; j < p - 1; j++) {
        deck[j + 50] = deck[j];
      }

      // 図の黄色の矢印の操作
      for (int j = 0; j < c; j++) {
        deck[j] = deck[j + p - 1];
      }

      // 退避させてたカードを戻す。図の青色の操作。
      for (int j = 0; j < p - 1; j++) {
        deck[c + j] = deck[j + 50];
      }
    }

    // デッキの一番上のカードを出力
    cout << deck[0] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <functional>

using namespace std;

int INF = 10000000;

int n , r;
int N[50];


int main()
{

	while(cin >> n >> r && n && r)
	{
		for(int i = 0;i < n;i++)N[i] = n-i-1;

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

			int temp;
			int t = 0;

			for(int j = p;j < p+c;j++)
			{
				temp = N[j];
				for(int k = 0;j-c-k >= 0;k++)
				{
					N[j-k] = N[j-c-k];
				}
				N[t] = temp;
				t++;
			}

		}

		cout << N[0]+1 << endl;



	}

  return 0;
}

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

using namespace std;

int n[10000]={},r[10000]={};
int p[10000][50] = {};
int c[10000][50] = {};
int i=0;

int d[50]={};
int e[50] = {}; //今の状態
int e2[50] = {};

int main(){
    while(1){
        scanf("%d %d",&n[i],&r[i]);
        if(n[i]== 0 && r[i]== 0){
            break;
        }
        for(int j=0;j<r[i];j++){
            scanf("%d %d",&p[i][j],&c[i][j]);
        }
        i++;
    }
    int times = i;
    for(i=0;i<times;i++){
        //初期化
        int s=0;
        for(int k = n[i]; k>0;k--){
            e[s] = k;
            s++;
        }
        for(int j=0;j<r[i];j++){
            s=0;
            for(int t=p[i][j]-1;t<p[i][j]+c[i][j]-1;t++){
                d[s] = e[t];
                s++;
            }
            for(int t = 0;t < n[i];t++){
                e2[t] = e[t];
            }
            for(int t = 0;t<c[i][j];t++){
                e[t] = d[t];
            }
            s = 0;
            for(int t=c[i][j];t<p[i][j]+c[i][j]-1;t++){
                e[t] = e2[s];
                s++;
            }
            for(int t=0;t<n[i];t++){
                cout<<e[t]<<endl;
            }
            puts("");

        }
        
        cout << e[0] << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(v) (v).begin(),(v).end()

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    while(1){
        int n;
        vector<int> vec;
        cin >> n;
        rep(i,n){
            vec.push_back(n-i);
        }
        int r;
        cin >> r;
        if(n == 0){
            break;
        }
        rep(i,r){
            int a,b;
            cin >> a >> b;
            vector<int> up;
            vector<int> bf;
            for(int i = a-1;i<a+b-1;i++){
                up.push_back(vec[i]);
            }
            rep(i,up.size()){
                bf.push_back(up[i]);
            }
            rep(i,a-1){
                bf.push_back(vec[i]);
            }
            for(int i = a+b-1;i < n;i++){
                bf.push_back(vec[i]);
            }
            vec.clear();
            vec = bf;
        }
        cout << vec[0] << "\n";
    }
	return 0;
}

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

using namespace std;

vector<int> data;

void shuffle(int p,int c){
  vector<int> tmp(c);
  for(int i=0;i < c;i++){
    tmp[i] = data[p+i];
  }
  data.erase(data.begin()+p, data.begin()+p+c);
  for(int i=0;i < c;i++){
    data.push_back(tmp[i]);
  }
}

int main(){
  int n, r, p, c;
  while(1){
    cin>> n >> r;
    if(!n && !r) break;
    data.reserve(n+1);
    for(int i=1;i<=n;i++){
      data.push_back(i);
    }
    for(int i=0;i<r;i++){
      cin>> p >> c;
      shuffle(p-1,c);
    }
    cout << data[data.size()-1] << endl;
    data.clear();
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<queue>
#include<map>
#define pb push_back
#define INF 1000000000

using namespace std;
int main(){
	int n,r;
	while(cin>>n>>r,n||r){
		vector<int> v(n);
		for(int i=0;i<n;i++){
			v[i]=n-i;
		}
		
		int p,c;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			vector<int> x;
			for(int j=0;j<p-1;j++){
				x.pb(v[j]);
			}
			vector<int> y;
			for(int j=p-1;j<c+p-1;j++){
				y.pb(v[j]);
			}
			for(int j=0;j<c;j++){
				v[j]=y[j];
			}
			for(int j=c;j<c+p-1;j++){
				v[j]=x[j-c];
			}
		}
		cout<<v[0]<<endl;
	}
	return 0;
}