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++: #pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
//typedef pair<ll,ll> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

signed main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);


    while(true){
        int N,R;
        cin>>N;
        if(N==0) return 0;
        cin>>R;
        vector<int> V[51];
        for(int i=N;i>=1;i--) V[0].push_back(i);

        for(int j=0;j<R;j++){
            int p,c;
            cin>>p>>c;
            for(int i=0;i<c;i++){
                int x=i+p-1;
                V[j+1].push_back(V[j][x]);
            }
            for(int i=0;i<N;i++){
                if(i>=p-1 && c+p-2>=i) continue;
                V[j+1].push_back(V[j][i]);
            }
        }
        cout<<V[R][0]<<endl;
    }
}

C++: #include <iostream>
using namespace std;
int card[50];
int buffer[50];
void 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(j=0;j<p-1;j++)
				buffer[j]=card[j];
			for(j=0;j<c;j++)
				card[j]=card[j+p-1];
			for(j=0;j<p-1;j++)
				card[j+c-1]=buffer[j];
		}
		cout<<card[0]<<endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,r,c,p;
    vector<int> s,s2;
    while(1){
        cin >> n >> r;
        if(n==0&&r==0)  break;
        for(int i=1;i<=n;i++){
            s.push_back(i);
        }
        while(r--){
            cin >> p >> c;
            for(int i=0;i<n-c-p+1;i++){
                s2.push_back(s[i]);
            }
            for(int i=n-p+1;i<n;i++){
                s2.push_back(s[i]);
            }
            for(int i=n-c-p+1;i<n-p+1;i++){
                s2.push_back(s[i]);
            }
            s.clear();
            for(int i=0;i<n;i++){
                s.push_back(s2[i]);
            }
            s2.clear();
        }
        cout << s[n-1] << "\n";
        s.clear();
    }
}

C++: #include <stdio.h>
#include <iostream>

using namespace std;

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

		if (r % 2 == 1 && c % 2 == 1) {
			cout << "no" << endl;
		}
		else {
			cout << "yes" << 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 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 cards;
	vector<PII> cuts;
	while(1){
		cards.clear();
		cuts.clear();
		cin >> n >> r;
		if(n == 0 && r == 0) break;
		rep(i,r){
			int p, c;
			cin >> p >> c;
			cuts.pb(mp(p, c));
		}
		rep(i, n){
			cards.pb(n - i);
		}
		rep(i, r){
			VI cs(n);
			int p = cuts[i].first;
			int c = cuts[i].second;
			int now = 0;
			REP(j, p - 1, p + c - 1){
				cs[now++] = cards[j];
			}
			rep(j, p){
				cs[now++] = cards[j];
			}
			REP(j, p + c, cards.size()){
				cs[now++] = cards[j];
			}
			cards = cs;
		}
		cout << cards[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 <vector>
#include <list>
#include <iostream>
#include <algorithm>

using namespace std;

list <int> hsf(list <int> li, int c, int p) {
  list <int> :: iterator i1, i2;
  list <int> :: iterator ii;

  if (p == 1) return li;

  i1 = i2 = li.begin();

  advance(i1, p-1);
  advance(i2, c + (p-1));

  li.splice(li.begin(), li, i1, i2);

  return li;

}


int main(void) {

  for (;;) {
    list <int> c1, c2;
    vector <int> c, p;
    int i, j;
    int n, r;

    cin >> n;
    cin >> r;
    if (n == 0 || r == 0) {
      break;
    }
    
    for (i = 0; i < r; i++) {
      int x, y;
      cin >> x;
      cin >> y;
      c.push_back(y);
      p.push_back(x);
    }

    for (j = 0; j < n; j++) {
      c1.push_front(j+1);
    }
  
    for (i = 0; i < r; i++) {
      c2 = hsf(c1, c[i], p[i]);
      c1 = c2;
    }

    list <int> :: iterator ii;

    ii = c1.begin();
    cout << *ii;
    cout << endl;
  }

  
  return 0;

}

C++: #pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    int n,r;
  while(1){
   cin>>n>>r;
   if(n==0||r==0)return 0;
   V<int> a(n);
   for(int i=0;i<n;i++)a[i]=i+1;
   reverse(all(a));
   int p,c;
   for(int i=0;i<r;i++){
       V<bool> used(n,false);
       V<int> tmp;
       cin>>p>>c;
       for(int j=p-1;j<p+c-1;j++){
            tmp.push_back(a[j]);
            used[j]=true;
       }
       for(int j=0;j<n;j++)if(!used[j])tmp.push_back(a[j]);
       a=tmp;
   }
   cout<<a[0]<<endl;
  }
}