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>

using namespace std;

int cards[51];

void cut_operation(int p, int c) {
  int tmp[51];
  int tmp2[51];
  for (int i = 0; i < p - 1; i++)  {
    tmp[i] = cards[i];
  }
  for (int i = 0; i < c; i++) {
    tmp2[i] = cards[p - 1 + i];
  }
  for (int i = 0; i < c; i++)  {
    cards[i] = tmp2[i];
  }
  for (int i = 0; i < p - 1; i++) {
    cards[i + c] = tmp[i];
  }
}

int main() {
  int n, r;
  while (true) {
    cin >> n >> r;
    if (n + r == 0) break;
    for (int i = 0; i < 51; i++) {
      cards[i] = n - i;
    }
    for (int i = 0; i < r; i++) {
      int p, c;
      cin >> p >> c;
      cut_operation(p, c);
    }
    cout << cards[0] << endl;
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(v) (v).begin(),(v).end()

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    while(1){
        int n;
        vector<int> vec;
        cin >> n;
        if(n == 0){
            break;
        }
        rep(i,n){
            vec.push_back(n-i);
        }
        int r;
        cin >> r;
        rep(i,r){
            int a,b;
            cin >> a >> b;
            vector<int> up;
            vector<int> bf;
            for(int i = a-1;i<a+b-1;i++){
                up.push_back(vec[i]);
            }
            rep(i,b){
                bf.push_back(up[i]);
            }
            rep(i,a){
                bf.push_back(vec[i]);
            }
            for(int i = a+b-1;i < n;i++){
                bf.push_back(vec[i]);
            }
            vec.clear();
            vec = bf;
        }
        cout << vec[0] << "\n";
    }
	return 0;
}

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

using namespace std;

int N, R, p, c;

int main()
{
	while (cin >> N >> R && N) {
		vector<int> A(N+1, 0);
		
		for (int i = 0; i < N; i++) {
			A[i] = N - i;
		}

		for (int i = 0; i < R; i++) {
			cin >> p >> c;
			rotate(A.begin(), A.begin() + p - 1, A.begin() + p + c - 1);	
		}

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

    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,r,p,c;
	int t[1000],a[1000],b[1000];
	while(cin>>n>>r,n||r){
		for(int i=0;i<n;i++)
		t[i]=n-i;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			for(int j=0;j<p-1;j++)
			a[j]=t[j];
			for(int j=0;j<c;j++)
			b[j]=t[j+p-1];
			for(int j=0;j<c;j++)
			t[j]=b[j];
			for(int j=0;j<p-1;j++)
			t[j+c]=a[j];
		}
		cout<<t[0]<<endl;
	}
	return 0;
}

C++: int main(){
  int n,k;
  while(1){
    cin >> n >> k;
    if(n==0&&k==0) break;
    vector<int> card(n+1,0);
    for(int i=1;i<n+1;++i) card[i]=n-i+1;

    //for(int i=1;i<n+1;++i){
      //cout << card[i] << endl;
    //}

    for(int i=0;i<k;++i){
      int p,c;
      cin >> p >> c;
      rotate(card.begin()+1,card.begin()+p,card.begin()+p+c);
      for(int j=1;j<n+1;++j){
	//cout << card[j] << endl;
      }
    }
    cout << card[1] << endl;
  }
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

using namespace std;

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;

int main(void) {
    while (true) {
        int n;
        int r;
        cin >> n >> r;
        if (n == 0) {
            break;
        }

        VI hana(n);
        for (int i = 0; i < n; i++) {
            hana[i] = n - i;
        }
        for (int i = 0; i < r; i++) {
            int p;
            int c;
            cin >> p >> c;
            VI temp(p - 1);
            for (int j = 0; j < p - 1; j++) {
                temp[j] = hana[j]; 
            }
            for (int j = 0; j < c; j++) {
                hana[j] = hana[j + p - 1]; 
            }
            for (int j = 0; j < p - 1; j++) {
                hana[j + c] = temp[j]; 
            }
        }
        cout << hana[0] << endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int input() {
	int input[51][2];
	cin >> input[0][0] >> input[0][1];								
	if (input[0][0] == 0 && input[0][1] == 0) {
		return 0;
	}
	for (char pos = 1; pos <= input[0][1]; pos++) {
		cin >> input[pos][0] >> input[pos][1];
	}																

	int whtop = 1;													
	whtop = input[input[0][1]][0];
	input[0][1]--;
	while (input[0][1] != 0) {

		if (input[input[0][1]][1] >= whtop) {
			whtop = input[input[0][1]][0] + whtop - 1;
		}
		else {
			whtop = whtop - input[input[0][1]][1];
		}
		input[0][1]--;
	}
	return input[0][0]-whtop+1;
}




int main()
{
	int output[1000];
	char topos = 0;
	while (1) {
		int check;
		check=input();
		if (check == 0)break;
		else {
			output[topos] = check;
			topos++;
		}
	}

	char sendpos = 0;
	while (sendpos < topos) {
		cout << output[sendpos] << endl;
		sendpos++;
	}


}

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

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