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 <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する

void solve(int n,int m){
    vector<int> v(n);
    rep(i,0,n){
        v[i] = i + 1;
    }
    rep(i,0,m){
        int p,c;
        cin >> p >> c;
        vector<int> tmp1(v.end() - p + 1 ,v.end());
        vector<int> tmp2(v.end() - p + 1 - c,v.end() - p + 1);

        rep(j,0,tmp1.size()){
            v[v.size() - p + 1 - c + j] = tmp1[j];
        }
        rep(j,0,tmp2.size()){
            v[v.size() - p + 1 - c + tmp1.size() + j] = tmp2[j];
        }


    }
    cout << v.back() << endl;

}

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

    while(true){
        int n,m;
        cin >> n >> m;
        if(n == 0) break;
        solve(n,m);

    }


    return 0;
}

C++: #include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


void printv(vector<int> v) {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i] << " ";
	}
	cout << endl;
}
int main() {
	
	while(1) {
		int n,r; cin >> n >> r;
		if(n + r == 0) {
			break;
		}

		vector<int> H(n,0);
		for (int i = 0; i < n; i++) {
			H[i] = n - i;
		}

		for (int j = 0; j < r; j++) {
			vector<int> a;
			vector<int> b;
			int p,c; cin >> p >> c;
			for (int i = 0; i < p-1; i++) {
				a.push_back(H[i]);
			}
			//cout << "a" << endl;
			//printv(a);
			for (int i = p - 1; i < p - 1 + c; i++) {
				b.push_back(H[i]);
			}
			//cout << "b" << endl;
			//printv(b);
		
			for (int i = 0; i < c; i++) {
				H[i] = b[i];
			}
			//cout << "H1" << endl;
			//printv(H);
			for (int i = 0; i < p - 1; i++) {
				H[c + i] = a[i];
			}
			//cout << "H2" << endl;
			//printv(H);
		}
		cout << H[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){
            int p,c;
            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>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mp make_pair

void solve(int N, vector<pii> &A) {
    vector<int> hana(N);
    for(int i = 0; i < N; i++) {
        hana[i] = N - i - 1;
    }
    for(int i = 0; i < A.size(); i++) {
        int p = A[i].first;
        int c = A[i].second;
        vector<int> newhana(N);
        for(int j = p; j < p + c; j++) {
            newhana[j - p] = hana[j];
        }
        for(int j = 0; j < p; j++) {
            newhana[c + j] = hana[j];
        }
        for(int j = 0; j < p + c; j++) {
            hana[j] = newhana[j];
        }
    }
    cout << hana[0] + 1 << endl;
}

int main() {
    int N, R;
    while(cin >> N >> R, R) {
        vector<pii> A(R);
        for(int i = 0; i < R; i++) {
            int p, c;
            cin >> p >> c;
            p -= 1;
            A[i] = mp(p, c);
        }
        solve(N, A);
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int N,R;
int D[2][55];
int main(){
  while( cin >> N >> R  && ( N|| R) ){
    for(int i=0;i<N;i++) D[0][i] = i+1;
    for(int i=0;i<R;i++){
      int P,C;
      cin >> P >> C;
      int in = N - (P-1) - C;
      for(int j=0;j<C;j++){
	D[1][in+(P-1)+j] = D[0][in+j];
      }
      for(int j=0;j<P-1;j++){
	D[1][in+j] = D[0][in+C+j];
      }
      for(int j=0;j<N;j++) D[0][j] = D[1][j];
    }
    cout << D[0][N-1] << endl;
  }
}

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

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

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    while(1){
        int n,r,i,p,c;
        cin>>n>>r;
        if(n==0) break;
        valarray<int> deck(n);
        for(i=0;i<n;i++){
            deck[i]=n-i;
        }
        for(i=0;i<r;i++){
            int j;
            cin>>p>>c;
            valarray<int> top = deck[slice(0,p-1,1)];
            valarray<int> mid = deck[slice(p-1,c,1)];
            for(j=0;j<mid.size();j++){
                deck[j]=mid[j];
            }
            for(;j<mid.size()+top.size();j++){
                deck[j]=top[j-mid.size()];
            }
        }
        cout<<deck[0]<<endl;
    }
    return 0;
}