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<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define ALL(c) (c).begin(), (c).end()
#define dump(a) cerr << #a << "=" << (a) << endl

using namespace std;

int cards[52];

int main() {
	int N,R; 
	int P,C;

	while(cin >> N >> R) {
		if (N == 0 && R == 0) break;
		//初期化
		rep(i,52) {
			cards[i] = 0;			
		}
		rep(i,N) {
			cards[i] = i+1;
		}


		//シャッフル
		vector<int> cards_p,cards_c;
		int center=0;
		rep(r,R) {
			cin >> P >> C;

			//コピー
			center = N-(P-1);
			REP(c,center-C,center) {
				cards_c.push_back(cards[c]);
			}
			REP(p,center,N) {
				cards_p.push_back(cards[p]);
			}
			
			//ペースト
			center = N-C;
			REP(p,center-(P-1),center) {
				cards[p] = cards_p.front();
				cards_p.erase(cards_p.begin());
			}
			REP(c,center,N) {
				cards[c] = cards_c.front();
				cards_c.erase(cards_c.begin());
			}
		}

		cout << cards[N-1] << endl;			
		
	}

	return 0;
}

C++: using namespace std;

int main(){
    int n,r,p,c,a[50];

    while(cin >> n >> r,n||r){
        for(int i=0;i<n;i++){
            a[i] = n-i;
        }

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

    return 0;

}

C++: #include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(void){

  while(true){
    int n, r;   cin >> n >> r;
    if(n == 0 && r == 0)    break;

    vector<int> yamahuda(n);
    for(int i = 0 ; i < n ; i++)  yamahuda[i] = i + 1;

    for(int i = 0 ; i < r ; i++){

      int p, c;   cin >> p >> c;
      vector<int> keep(c);
      for(int i = 0 ; i < c ; i++)
        keep[i] = yamahuda[n - p - c  + 1 + i];

      for(int i = 0 ; i < p - 1 ; i++)
        yamahuda[n - p - c + 1 + i] = yamahuda[n - p + 1 + i];

      for(int i = 0 ; i < c ; i++)
        yamahuda[n - c + i] = keep[i];

    }

    cout << yamahuda[n - 1] << endl;

  }

  return 0;
}

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

using namespace std;

#define P(a,n) for (int k = 0; k < n; k++) printf("%d ", a[k]);

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

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

int n, r, p, c;
int h[51];

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

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

using namespace std;

int main(){
  int n,r,p,c;
  while(1){
    cin >> n >> r;
    if (n==0) return 0;
    vector<int> ca(n,0);
    for(int i=0;i<n;i++){
      ca[i]=n-i;
    }
    for(int i=0;i<r;i++){
      cin>>p>>c;
      vector<int>sw(c,0);
      for(int j=0;j<c;j++){
        sw[j]=ca[p-1];
        ca.erase(ca.begin()+p-1);
      }
      for(int j=c-1;j>=0;j--){
        ca.insert(ca.begin(),sw[j]);
      }
    }
    cout << ca[0]<<endl;
  }
}

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

int main(void){
  while(1){
    vector<int> f;
    int n, r, p, c;
    cin >> n >> r;
    if(n == 0 && r == 0) return 0;
    for(int i=n; i >= 0; i--){
      f.push_back(i);
    }


    for(int i=0; i < r; i++){
      cin >> p >> c;
      vector<int> t;
      for(int j=p-1; j < p+c; j++){
        t.push_back(f.at(j));
      }
      for(int j=p-1; j > 0; j--){
        f.at(j+c) = f.at(j);
      }
      for(int j=0; j < c; j++){
        f.at(j) = t.at(j);
      }


    }
    cout << f.front() << endl;
  }
}

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

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

	for(int n, r; cin >> n >> r, n;) {
		vector<int> cards;
		cards.reserve(n);
		for(int i = n; i > 0; --i)
			cards.push_back(i);

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

			vector<int> tmp(cards);
			for(int i = 0; i < p - 1; ++i)
				tmp[i + c] = cards[i];

			for(int i = 0; i < c; ++i)
				tmp[i] = cards[i + p - 1];

			cards.swap(tmp);
		}

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

	return EXIT_SUCCESS;
}

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

int main() {
	int n, r, p, c, i, ans;
	
	while (cin >> n  && cin >> r) {
		int Deck[51];

		if (n == 0 && r == 0) {
			break;
		}

		for (i = 0; i < n; i++) {
			Deck[i] = n-i;
		}

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

			rotate(Deck, Deck + p - 1, Deck + p + c - 1);
		}

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