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>
using namespace std;

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int n,r;
	while(true){
		cin >> n >> r;
		if(!n&&!r) break;
		vector<int> fuda;
		REP(i,n) fuda.push_back(i+1);
		REP(i,r){
			int p, c;
			cin >> p >> c;
			for(int j=c-1;j>=0;j--){
				fuda.push_back(fuda[n-p-j]);
			}
			REP(i,c)fuda.erase(fuda.begin()+n-p-i);
		}
		cout << fuda[n] << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()

using namespace std;

const int INF = 1000000000;
const double eps = 1e-8;

int main(void) {
  while(1){
    int n,r;cin>>n>>r;
    if(!(n||r))break;
    vector<int> a(n);
    iota(a.rbegin(),a.rend(),1);
    REP(i,r){
      int p,c;cin>>p>>c;
      vector<int> t(n);
      REP(j,c)t[j]=a[j+p-1];
      REP(j,p-1)t[j+c]=a[j];
      FOR(j,c+p-1,n)t[j]=a[j];
      swap(a,t);
    }
    cout<<a[0]<<endl;
  }
  return 0;
}

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

using namespace std;

void shuffle(int *cards,int p, int c){
	int *mt1 = new int[p-1];
	for(int i=0;i<p-1;i++){
		mt1[i] = cards[i];
	}	
	int *mt2 = new int[c];
	for(int i=0;i<c;i++){
		mt2[i] = cards[p-1+i];
	}
	for(int i=0;i<c;i++){
		cards[i] = mt2[i];
	}
	for(int i=0;i<p-1;i++){
		cards[c+i] = mt1[i];
	}
	delete[] mt1;
	delete[] mt2;
}

int main(){
	int n,r;//カードの枚数,シャッフルの回数
	while(true){
		cin >> n >> r;
		if(n==0 && r==0){
			break;
		}
		int *cards = new int[n];
		for(int i=0;i<n;i++){
			cards[i] = n-i;
		}
		for(int i=0;i<r;i++){
			int p,c;//上からpの場所からc個
			cin >> p >> c;
			shuffle(cards,p,c);
		}
		int result = cards[0];
		cout << result << endl;
		delete[] cards;
	}
	
	return 0;
}

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

int main(){
	int n,r,p,c;
	int a[50],buf[50];
	while(cin>>n>>r,n|r){
		for(int i=0;i<n;i++)a[i]=n-i;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			p--;
			memcpy(buf,a,p*sizeof(int));
			memmove(a,a+p,c*sizeof(int));
			memcpy(a+c,buf,p*sizeof(int));
		}
		cout<<a[0]<<endl;
	}
	return 0;
}

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

int main(){
    int n,r;
    while(cin>>n>>r){
        if(n==0 and r==0) return 0;
        vector<int> card(n);
        for(int i=0;i<n;i++) card[i] = n-i;
        for(int count=0;count<r;count++){
            int p,c;cin>>p>>c;
            p--;
            //card[p] ... card[p+c-1]????????????????????£?????????
            vector<int> tmp(c);
            for(int i=0;i<c;i++) tmp[i] = card[p+i];

            vector<int> cash;
            for(int i=0;i<c;i++) cash.push_back(tmp[i]);
            for(int i=0;i<p;i++) cash.push_back(card[i]);
            for(int i=p+c;i<n;i++) cash.push_back(card[i]);
            card = cash;
        }
        cout << card[0] << endl;
    }
}

C++: #include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000



int main(){
  int card[50];
  int tmp[50];

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

    rep(i,n) card[i]=n-i;

    rep(i,r){
      int p,c;
      scanf("%d %d", &p, &c);
      p--;

      rep(j,c){
	tmp[j]=card[p+j];
      }
      rep(j,p){
	card[c+p-j-1] = card[p-j-1];
      }
      rep(j,c){
	card[j]=tmp[j];
      }
    }

    cout << card[0] << endl;

  }

}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a ; i<b ; i++)
#define dump(x) cout << #x << " = " << x << endl

using namespace std;

int card[50];
int n, r;

void disp(){
	rep(i,0,n) cout << card[i] << " ";
	cout << endl;
	return ;
}

int main(){

	while(1){
		cin >> n >> r;
		if(n==0) break;

		rep(i,0,n) card[i] = n - i;
		disp();

		rep(i,0,r){
			int p, c;
			cin >> p >> c;
			int temp[p];

			rep(i,0,p-1) temp[i] = card[i];
			rep(i,0,c) card[i] = card[p-1+i];
			rep(i,0,p-1) card[c+i] = temp[i];

			// disp();

		}

		cout << card[0] << endl;

	}
	return 0;
}

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]=n-i;
		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 <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
  
int main()
{
	int n,m;
	int p[51]={0};
	int c[51]={0};
	int i;
	int ans;

	while(1)
	{
	scanf("%d %d",&n,&m);
	if((n==0)&&(m==0))
		break;
	ans=n;

	for(i=1;i<=m;i++){
		scanf("%d %d",&p[i],&c[i]);	
	} 

	for(i=m;i>=1;i--){
		if(p[i]!=1){
		if((n-p[i]+1-c[i]-1)>=ans){
		}else if(ans>=(n-c[i]-1)){
			ans = ans-p[i]+1;
		}else
			ans = ans+c[i];
		}
	}
	printf("%d\n",ans);

	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(x) x.begin(),x.end()
#define ll long long
using namespace std;

void shuf(vector<int> &v,int p,int c){
    p-=1;
    vector<int> tmp1(p,0),tmp2(c,0);
    rep(i,p){
        tmp1[i]=v[i];
    }
    rep(i,c){
        tmp2[i]=v[p+i];
    }
    rep(i,c){
        v[i]=tmp2[i];
    }
    rep(i,p){
        v[c+i]=tmp1[i];
    }

}

int main(){
    while (true){
        int n,r;
        cin>>n>>r;
        if (n==0)
            break;
        vector<int> deck(n,0);
        rep(i,n){
            deck[n-i-1]=i+1;
        }
        rep(i,r){
            int p,c;
            cin>>p>>c;
            shuf(deck,p,c);
        }
        cout<<deck[0]<<endl;
    }

}

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

int main() {
int N,R,p,c;
while (cin>>N>>R&&N) { 
	int A[100]={};
	for(int i=0;i<N;i++){
		A[i]=i+1;
	}
	
	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 <algorithm>

#define range(i,a,b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i,n) range(i,0,n)

using namespace std;

int a[110];

int main(void){
	int n,r;
	while(cin >> n >> r,n|r){
		rep(i,n) a[i]=n-i;
		//cout << a[0] << a[1] << endl;
		rep(i,r){
			int p,c;
			cin >> p >> c;
			int tmp[110];
			rep(i,p-1) tmp[i]=a[i];
			rep(i,c) a[i]=a[i+p-1];
			rep(i,p-1) a[i+c]=tmp[i];
		}
		cout << a[0] << endl;
	}
	return 0;
}