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;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

ll v[100];

int main()
{
	while (1) {
		cin >> n >> k;
		if (n == 0 && k == 0) {
			return 0;
		} else {
			vi v(n + 1);
			REP(i, n + 1)
				v[i] = n + 1 - i;
			REP(i, k)
			{
				ll p, c;
				cin >> p >> c;
				REP(j, c)
				{
					ll tmp = v[p + j];
					for (int l = p; l >= 1; l--) {
						v[j + l] = v[j + l - 1];
					}
					v[j + 1] = tmp;
				}
			}
			cout << v[1] << endl;
		}
	}
}

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

int main() {

    int n, m, p, c, ans;
    string str;
    for (; ;) {
        scanf("%d %d", &n, &m);
        if (n == 0 && m == 0) break;
        str = "";
        for (int i = n; i >= 1; i--) {
            if (i < 10) str+='0';
            str+= to_string(i);
        }
        for (int i = 0; i < m; i++) {
            scanf("%d %d", &p, &c);
            str = str.substr(p*2-2, c*2)+str.substr(0,p*2-2)+str.substr(p*2-2+c*2);
        }
        printf("%d\n", stoi(str.substr(0, 2)));
    }
    return 0;
}

C++: //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1129&lang=jp
//

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

void show(int *a,int x){
    for(int i =0;i<x;i++){
        cout << a[i] << endl;
    }
}
int main() {
    int N,R;
    int A[2][55];
    int p,c;
    while(cin >> N >> R && N) {
        for(int i=0; i<N; ++i){
            A[0][i] = N - i;
            
        }
        int now = 0;
        int next = 1;
        rep(i,R){
            cin >> p >> c;
            rep(j,c){
                A[next][j] = A[now][p-1+j];
            
            }
            for(int j=p-1+c; j<N; j++){
                A[next][j] = A[now][j];
            
            }
            for(int j=0; j<p-1; ++j){
                A[next][c+j] = A[now][j];
            }
            int temp = now;
            now = next;
            next = temp;
            
            
        }
        cout << A[now][0] << endl;
        
    }
    
    return 0;
}

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

using namespace std;

const void ShowList(list<int>);

int main() {
	//ifstream fin("input.txt");

	if (!fin)return -1;

	list<int> stock;

	while (true) {

		int number = 0;
		int shuffleCount = 0;
		int top = 0;

		cin >> number >> shuffleCount;
		if (number == 0 && shuffleCount == 0)break;

		//????????????????´??????????(?±±?????????)
		for (int i = 1; i <= number; i++) {
			stock.push_front(i);
		}

//		ShowList(stock);
		list<int>::iterator begin;
			list<int>::iterator end;

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

			if (number == c)continue;
			begin = stock.begin();
			advance(begin, p - 1);
//			cout << "\t" << *begin << endl;

			end = begin;
			advance(end, c);
//			cout << "\t" << *end << endl;

			stock.splice(stock.begin(), stock, begin, end);

		}
//		ShowList(stock);
		cout << stock.front() << endl;

		stock.clear();
	}
	return 0;
}

const void ShowList(list<int> lst){
	list<int>::iterator a = lst.begin();
	for (int i = 0; i < lst.size(); i++) {
		cout << *a << " ";
		a++;
	}
	cout << endl;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  while (true) {
    int n, r;
    cin >> n >> r;
    if (n == 0) return 0;
    vi a(n);
    rep (i, n) {
      a[i] = n - i;
    }
    rep (i, r) {
      int p, c;
      cin >> p >> c;
      p--;
      vi temp;
      for (int j = p; j < p + c; j++) {
        temp.push_back(a[p]);
        a.erase(a.begin() + p);
      }
      temp.insert(temp.end(), a.begin(), a.end());
      a = temp;
    }
    cout << a[0] << endl;
  }
}

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

using namespace std;

int main(){
    for (; ;) {
        int n, r;
        cin >> n >>r;
        if (n==0&&r==0) {
            break;
        }
        vector<int> yama(n);
        for (int i=0; i<n; i++) {
            yama[i]=n-i;
        }
        for (int i=0; i<r; i++) {
            int p ,c;
            cin >> p >> c;
            vector<int> temp(c);
            for (int j=0;j<c; j++) {
                temp[j]=yama[p-1+j];
            }
            for (int j=p-2; j>=0;j--) {
                yama[c+j]=yama[j];
            }
            for (int j=0; j<c; j++) {
                yama[j]=temp[j];
            }
            }
        cout <<yama[0]<<endl;
}
}