Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		n, _ := strconv.Atoi(chunks[0])
		r, _ := strconv.Atoi(chunks[1])
		cards := make([]int, n, n)
		for i := 0; i < n; i++ {
			cards[i] = n - i
		}
		for i := 0; i < r; i++ {
			sc.Scan()
			chunks := strings.Split(sc.Text(), " ")
			p, _ := strconv.Atoi(chunks[0])
			c, _ := strconv.Atoi(chunks[1])
			block := make([]int, c, c)
			for j := 0; j < c; j++ {
				block[j] = cards[p+j-1]
			}
			for j := p - 2; j >= 0; j-- {
				cards[j+c] = cards[j]
			}
			for j := 0; j < c; j++ {
				cards[j] = block[j]
			}
		}
		fmt.Println(cards[0])
	}
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,R;
    cin >> N >> R;
    while(N){
        vector<int> V(N);
        iota(V.rbegin(), V.rend(), 1);
        for(auto i:V)cout << i << endl;
        rep(i,0,R){
            int p,c;
            cin >> p >> c;
            vector<int> tmp(p + c - 1);
            rep(j,0,c){
                tmp[j] = V[j + p - 1];
            }
            rep(j,c,p+c-1){
                tmp[j] = V[j-c];
            }
            rep(j,0,p+c-1){
                V[j] = tmp[j];
            }
        }
        cout << V[0] << endl;
        cin >> N >> R;
    }
}

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

using namespace std;

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long

//constant
const int MOD = 1000000009;
//const int INF = INT_MAX / 3;

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
	int n, r;
	while (cin >> n >> r, n) {
		vi st(n);
		REP(i, n)
			st[i] = n-i ;

		REP(i, r) {
			vi sw(n);
			REP(i, n)
				sw[i] = st[i];
			int p, c;
			cin >> p >> c;
			REP(j, c)
				sw[j] = st[p-1  + j];
			REP(j, p-1)
				sw[j + c] = st[j];


			REP(i, n)
				st[i] = sw[i];

		}

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

	return 0;
}

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

int main(){
  int n,r, start, end;
  vector<int> ans;
  cin >> n >> r;
  while(n||r){
    vector<int> data(n);
    for(int i = 0; i <n;i++){
      data[i] = n-i;
    }
    for(int j = 0; j < r ; j++){
      cin >> start >> end;
      for(int k = 0; k < end;k++){
        int a = data[start+k-1];
        for(int forth = start-1; forth > k; forth--){
          data[k+forth] = data[k+forth-1];
        }
        data[k] = a;
      }
    }
    ans.push_back(data[0]);
    cin >> n >> r;
  }
  for(int i =0;i<(int)ans.size();i++){
    cout << ans[i] << endl;
  }
}

C++: #include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (int)(a); v < (int)(b); ++v)
#define FORE(v, a, b) for(int v = (int)(a); v <= (int)(b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define PF push_front
#define ALL(x) (x).begin(), (x).end()
using namespace std;

void split(string str, char chr, vector< string > *res){
	stringstream ss(str);
	string itm;
	while(getline(ss, itm, chr)){
		(*res).PB(itm);
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, r, p, c;
	list< int > l1, l2;
	
	while(cin >> n >> r, n){
		l1.CLR();
		l2.CLR();
		
		REP(i, n){
			l1.PF(i + 1);
		}
		
		REP(i, r){
			cin >> p >> c;
			
			list< int >::iterator bitr = l1.begin(), eitr = l1.begin();
			advance(bitr, p - 1);
			advance(eitr, p + c - 1);
			
			l2.splice(l2.begin(), l1, bitr, eitr);
			
			l1.splice(l1.begin(), l2);
		}
		
		cout << l1.front() << endl;
	}
	
	return 0;
}

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

#define FOR(i,a,n) for(int i = a;i<n;i++)
#define REP(i,n) FOR(i,0,n)
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) SET(a,0)
#define MAX(a,b) (a>b)?a:b
#define MIN(a,b) (a<b)?a:b

using namespace std;

int deck[50];
int bucket[50];
int n,r;

void init(){
  REP(i,n) deck[i] = n-i;
}

int solve(){
  int p,c;
  init();
  REP(i,r){
    cin >> p >> c;
    REP(j,c){
      bucket[j] = deck[p+j-1];
    }
    for(int j = p-2;j >= 0;j--){
      deck[j+c] = deck[j];
    }
    REP(j,c){
      deck[j] = bucket[j];
    }
  }
  return deck[0];
}

int main(){
  while(true){
    cin >> n >> r;
    if((n|r) == 0) break;
    cout << solve() << endl;
  }
  
}

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

int main() {
int n,r,p,d;
while(cin>>n>>r){
	if(n==0&&r==0){
		break;
	}
	int a[50]={},b[50]={},c[50]={};
	for(int k=0;k<n;k++){
		a[k]=n-k;
	}
	for(int i=0;i<r;i++){
		cin>>p>>d;
		for(int l=0;l<p-1;l++){
			b[l]=a[l];
		}
		for(int m=0;m<d;m++){
			c[m]=a[p+m-1];
		}
		for(int o=0;o<d;o++){
			a[o]=c[o];
		}
		for(int z=0;z<p-1;z++){
			a[d+z]=b[z];
		}
	}
		cout<<a[0]<<endl;
	}
	return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n,r,p,c;
	while(cin >> n >> r, n+r){
		int huda[50], tmp[50];
		for(int i=0; i<n; i++){
			huda[i]	= n-i;
			tmp[i] = n-1;
		}
		for(int i=0; i<r; i++){
			cin >> p >> c;
			for(int j=0; j < p+c-1; j++){
				if(j<p-1){
					tmp[j+c] = huda[j];
				}else{
					tmp[j-p+1] = huda[j];
				}
			}
			for(int j=0; j<n; j++){
				huda[j] = tmp[j];	
			}
		}
		cout << huda[0] << "\n";
	}
}

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

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

using namespace std;

typedef vector<int> V;

int n, r;
V x;

int main(){
	while(scanf("%d%d", &n, &r), n){
		rep(i, n){
			x.push_back(n - i);
		}
		
		rep(i, r){
			int p, c;
			scanf("%d%d", &p, &c);
			V::iterator a = x.begin() + p - 1;
			V::iterator b = a + c;
			vector<int> y(a, b);
			x.erase(a, b);
			x.insert(x.begin(), y.begin(), y.end());
		}
		printf("%d\n", x[0]);

		x.clear();
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
const double PI=acos(-1.0);
//---------------------------------------------------------------------------//
int n,r,p1,c;
int huda[51],huda2[51];
int main(){
        while(1) {
                cin>>n>>r;
                if(n==0 && r==0) {
                        return 0;
                }
                for(int i=0; i<r; i++) {
                        cin>>p1>>c;
                        for(int j=0; j<n; j++) {
                                huda[i]=n-i;
                                huda2[i]=huda[i];
                        }
                        for(int j=0; j<c; j++) {
                                huda[j]=huda[p1-1+j];
                        }
                        for(int j=0; j<p1-1; j++) {
                                huda[c+j]=huda2[j];
                        }
                        for(int j=0; j<51; j++) {
                                huda2[j]=huda[j];
                        }
                }
                cout<<huda[0]<<endl;
        }
}