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>
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]);
			}

			for(int j=0;j<c;j++){
				fuda.erase(fuda.begin());
			}
		}
		cout << fuda[n] << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
ll MIN(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}//pは素数,aのb乗をpで割った余り
ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}//pは素数,(nCr)%p
ll gcd(ll a, ll b) {

	if (a < b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	if (a%b == 0)return b;
	return gcd(b, a%b);

}//最大公約数
ll lcm(ll a, ll b) {

	return a / gcd(a, b)*b;

}//最小公倍数

int main() {
	
	while(1){
		int N,R;
		cin>>N>>R;
		if(N==0&&R==0)break;
		vector<int> V;
		for(int i=0;i<N;i++){
			V.pb(N-i);
		}
		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(V[p-1+j]);
			}
			for(int j=0;j<p-1;j++){
				tmp.pb(V[j]);
			}
			for(int j=0;j<N-(p-1)-c;j++){
				tmp.pb(V[p-1+c+j]);
			}
			V=tmp;
		}
		cout<<V[0]<<endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main(){
  int n,r;
  while(1){
    cin >> n >> r;
    if(n==0&&r==0)break;
    int p,c;
    vector<int> bef(n);
    vector<int> aft(n);
    rep(i,n){
      bef[i] = n-i;
    }
    rep(i,r){
      cin >> p >> c;
      for(int j=0;j<c;j++){
        aft[j]=bef[p-1+j];
      }
      for(int j=0;j<p-1;j++){
        aft[c+j]=bef[j];
      }
      for(int j=c+p-1;j<n;j++){
        aft[j]=bef[j];
      }
      bef=aft;
    }
    cout << bef[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]=i+1;
		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-1]=buffer[j];
		}
		cout<<card[0]<<endl;
	}
	return 0;
}

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

using namespace std;

int main() {
    while(true) {
        int N, R;
        cin >> N >> R;
        if(!N && !R) break;

        vector<int> cards(N);
        for(int i = 0; i < N; ++i) cards[i] = N-i;

        while(R--) {
            int P, C;
            cin >> P >> C;
            P--;
            vector<int> tmp;
            for(int i = 0; i < C; ++i) tmp.push_back(cards[P+i]);
            for(int i = 0; i < P; ++i) tmp.push_back(cards[i]);
            for(int i = P+C; i < N; ++i) tmp.push_back(cards[i]);
            cards = tmp;
        }

        cout << cards[0] << endl;
    }
    return 0;
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while(true){
	int N, R; cin >> N >> R;
	if(N == 0 && R == 0) break;
	VI card(N+1);
	REP(i,N+1)
	  card[i] = N + 1 - i;
	REP(r,R){
	  int p, c; cin >> p >> c;
	  for(int i=0;i<c;++i){
		int tmp = card[p + i];
		for(int j=p;j>=1;--j)
		  card[i+j] = card[i+j-1];
		card[i+1] = tmp;
	  }
	  //	  for(int i=1;i<=N;++i)cout<<card[i]<<endl;cout<<endl;
	}
	cout << card[1] << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main()
{
	int n,r;
	while(cin>>n>>r,n) 
	{
		string deck;
		for(int i = n; 0 < i; --i)
		{
			deck+='0'+i;
		}

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

			string t,m,b;
			t=deck.substr(0,p-1);
			m=deck.substr(p-1,c);
			b=deck.substr(p-1+c-1);

			deck=m+t+b;
		}
		cout<<deck[0]<<endl;
	}
  return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define REP(i,k,n) for(int i = k; i < n; i++)

#define vi vector<int>
#define pb push_back
using namespace std;

int main(){
    int n,r;
    while(cin >> n >> r,n) {
        vi card(n);

        rep(i,n) card[i] = n - i;
        rep(i,r){
            cin >> p >> c;
            vi tmp(c);
            rep(j,c) tmp[c] = card[p - 1 + j];
            rrep(j,p - 1) card[j + c - 1] = card[j];
            rep(j,c) card[j] = tmp[c];
        }
        cout << card[0] << endl;
    }
    return 0;

}

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

int main(){
	while(1){
		int n,r,p,c;
		cin >> n >> r;
		if(n == 0 && r ==0)break;
		int s[n + 1];
		for(int i = 1; i <= n;++i){
		s[i] = i;
		}
		for(int j = 0; j < r;++j){
			cin >> p >> c;
			if(p == 1)continue;
			for(int k = 0;k < c;++k){
				s[0] = s[n + 2 - p - c];
				for(int l = 0;l < p + c - 2;++l){
					s[n + 2 - p - c + l] = s[n + 3 - p - c + l];
					}
				s[n] = s[0];
			}
		}
		  cout << s[n] << endl;

	}
	return 0;
}