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 <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)

int main() {
	int N,R;
	while(cin>>N>>R && N>0 && R>0){
		int p[R],c[R];
		Rep(i,R) cin>>p[i]>>c[i];
		int card[N];
		Rep(i,N) card[i] = N - i;
		Rep(i,R) rotate(card,card+p[i]-1,card+p[i]+c[i]-1);
		cout<<card[0]<<endl;
	}
	return 0;
}

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

int main(){
  int n, r;
  while(cin >>n >>r && n){
    vector<int> v;
    for(int i = n; i > 0; i--) v.push_back(i);

    rep(i, r){
      int p, c;
      cin >>p >>c;
      vector<int> next;
      for(int i = 0; i < c; i++) next.push_back(v[p - 1 + i]);
      for(int i = 0; i < p - 1; i++) next.push_back(v[i]);
      for(int i = p + c - 1; i < v.size(); i++) next.push_back(v[i]);
      v = next;
    }
    cout <<v[0] <<endl;
  }
  return 0;
}

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

//?±±?????????????????¢??°???????±±???????±±????????°n???p?????????????????????c???                       
void shuffle(vector<int> &yama, int n, int p, int c);


int main(){
  int n, r;
  int p, c;
  vector<int> yama, v;

  cin >> n;
  cin >> r;

  while(n != 0 && r != 0){
    //?±±??????????????????                                                            
    yama.clear();
    for(int i = 0, j = n; i < n; i++, j--){
      yama.push_back(j);
    }
    //?????£?????????                                                                
    for (int i = 0; i < r; i++){
      cin >> p;
      cin >> c;
      shuffle(yama, n, p, c);
    }
    //???????????????????¨????                                                          
    v.push_back(yama.front());

    cin >> n;
    cin >> r;
  }
  for(int i = 0; i < v.size(); i++){
    cout << v[i] << endl;
  }
  cout << endl;
}

void shuffle(vector<int> &yama, int n, int p, int c){
  int tmp;

  for(int i = 0;i < c; i++){
    tmp = yama[p-1+c-1];
    yama.erase(yama.begin()+p-1+c-1);
    yama.insert(yama.begin(), tmp);
    for(int j = 0; j < yama.size(); j++){
      cout << yama[j] << " ";
    }
    cout << endl;

  }
}

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

int main() {
  while(true) {
    int ncard, r;
    cin >> ncard >> r;
    if(ncard == 0 && r == 0) break;
    vector<int> cards(ncard);
    for(int i = 0; i < ncard; ++i) cards[i] = ncard - i;
    for(int i = 0; i < r; ++i) {
      int p, c;
      vector<int> results;
      scanf("%d%d", &p, &c);
      for(int j = p - 1; j < p - 1 + c; ++j) {
        results.push_back(cards[j]);
      }
      for(int j = 0; j < p - 1; ++j) {
        results.push_back(cards[j]);
      }
      for(int j = p - 1 + c; j < ncard; ++j) {
        results.push_back(cards[j]);
      }
      cards = results;
    }
    cout << cards[0] << endl;
  }
  return 0;
}