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;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

template<typename T> ostream& operator <<(ostream& r, const vector<T> t){vrep(v,t)r<<*v<<(v+1==t.end()?"":" ");return r;}
template<typename T> ostream& operator <<(ostream& r, const pair<vector<T>, int> p){int n=p.second;minup(n,p.first.size());rep(i,n-1)r<<p.first[i]<<' ';r<<p.first[n-1];return r;}
template<typename T> ostream& operator <<(ostream& r, const pair<T*, int> p){int n=p.second-1;rep(i,n)r<<p.first[i]<<' ';return r<<p.first[n];}
template<typename T, size_t S> ostream& operator <<(ostream& r, const T (&a)[S]){rep(i,S-1)r<<a[i]<<' ';return r<<a[S-1];}


int n, r;
int x, y;

int main()
{
  while((cin >> n >> r) && n){
    vi card(n);
    rep(i, n) card[i] = n - i;
    while(r--){
      cin >> x >> y;
      x -= 1;
      vi tmp;
      erep(i, x, x + y) tmp.pb(card[i]);
      rev(i, x) card[i + y] = card[i];
      rep(i, y) card[i] = tmp[i];
    }
    cout << card[0] << endl;
  }

  return 0;
}

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

//?±±?????????????????¢??°???????±±???????±±????????°n???p?????????????????????c???                       
void shuffle(vector<int> &yama, int n, int p, int c);


int main(){
  int n, r;
  int p, c;
  vector<int> yama, v;

  cin >> n;
  cin >> r;

  while(n != 0 && r != 0){
    //?±±??????????????????                                                            
    yama.clear();
    for(int i = 0, j = n; i < n; i++, j--){
      yama.push_back(j);
    }
    //?????£?????????                                                                
    for (int i = 0; i < r; i++){
      cin >> p;
      cin >> c;
      shuffle(yama, n, p, c);
    }
    //???????????????????¨????                                                          
    v.push_back(yama.front());

    cin >> n;
    cin >> r;
  }
  for(int i = 0; i < v.size(); i++){
    cout << v[i] << endl;
  }
}

void shuffle(vector<int> &yama, int n, int p, int c){
  int tmp;

  for(int i = 0;i < c; i++){
    tmp = yama[p-1+c-1];
    yama.erase(yama.begin()+p-1+c-1);
    yama.insert(yama.begin(), tmp);

  }
}

C++: #include<iostream>

using namespace std;

int y[51], t[51];
int n, r;

void set_yama(int n){
    for(int i=0; i<n; i++){
        y[i] = i + 1;
    }
}

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

        for(int j=0; j<c; j++){
            t[c-1-j] = y[n-p-j];
        }

        for(int j=n-p+1; j<n; j++){
            y[j-c] = y[j];
        }

        for(int j=0; j<c; j++){
            y[n-c+j] = t[j];
        }
    }
}

int main(void){

    while(1){
        cin >> n >> r;
        if(n==0 || r==0){
            break;
        }
        
        set_yama(n);
        shuffle(n, r);
        cout << y[n-1] << endl;
    }
    return 0;
}

C++: #include <iostream>
#define MAX_R 50
#define MAX_N 50

using namespace std;
void solve();

int c[MAX_R],p[MAX_R],n,r;

int main()
{
    while (1) {
        cin>>n>>r;
        if (n==0&&r==0) break;
        for (int i=0; i<r; i++) cin>>p[i]>>c[i];
        solve();
    }
}

void solve()
{
    int card[MAX_N];
    for (int i=n-1; i>=0; i--) card[i]=n-i;
    for (int i=0; i<r; i++) {
        int cut[MAX_N];
        for (int j=0; j<c[i]; j++) cut[j]=card[p[i]+j-1];
        for (int j=p[i]-2; j>=0; j--) card[j+c[i]]=card[j];
        for (int j=0; j<c[i]; j++) card[j]=cut[j];
    }
    cout<<card[0]<<endl;
}

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

using namespace std;

#define ll long long
#define pb push_back

ll MIN(ll num1,ll num2){
    return num1<num2?num1:num2;
}

int main(){

    while(1){
        int n,r;
        vector<int> P,C,card;
        cin>>n>>r;
        if(n==0&&r==0)break;
        for(int i=n;i>0;i--){
            card.pb(i);
        }
        //for(int j=0;j<n;j++)cout<<card[j]<<" ";
        //cout<<endl;
        for(int i=0;i<r;i++){
            int p,c;
            cin>>p>>c;
            vector<int> tmp;
            for(int j=0;j<c;j++){
                tmp.pb(card[p-1+j]);
                //cout<<card[p-1+j]<<" ";
            }
            //cout<<endl;
            for(int j=0;j<p-1;j++){
                tmp.pb(card[j]);
                //cout<<card[j]<<" ";
            }
            //cout<<endl;
            for(int j=0;j<n-p+1-c;j++){
                tmp.pb(card[p-1+c+j]);
                //cout<<card[p-1+c+j]<<" ";
            }
            //cout<<endl;
            card=tmp;
            //for(int j=0;j<n;j++)cout<<card[j]<<" ";
            //cout<<endl<<endl;
        }
        cout<<card[0]<<endl;
    }

    return 0;
}

C++: #define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e9
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	while (true) {
		int n, r;
		cin >> n >> r;
		if (n == 0) return 0;
		vector<int> hana;
		REP(i, n) {
			hana.push_back(n - i);
		}
		REP(i, r) {
			int a, b;
			cin >> a >> b;
			vector<int> new_hana;
			for (int q = 0; q < b; ++q) {
				new_hana.push_back(hana[q + (a-1)]);
			}
			for (int q = 0; q < hana.size(); ++q) {
				if (q < a - 1 || a - 1 + b <= q) {
					new_hana.push_back(hana[q]);
				}
			}
			hana = new_hana;
		}
		cout << hana[0] << endl;
	}
}

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

using namespace std;
int n, r, p, c;

int main(){
	while (cin >> n >> r && n){
		int a[n];
		for (int i = 0; i < r; i++){
			a[n-i-1] = i + 1;
		}
		for (int j = 0; j < r; j++){
			cin >> p >> c;
			rotate(a, a + p-1, a + p + c-1);
		}
		cout << a[0] << endl;
	}
	return 0;
}