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 <stdio.h>
??
int main() {
??
????int r,d,n,i,j,k,l;
????int p,c;
????int a[60] = {0};
????int b[60] = {0};
??
??
????while(1) {
??
????????scanf("%d %d", &n, &r);
??
????????if(n == 0 && r == 0) {
????????????break;
????????}
??
??
????????for(i =0 ; i<=n ; i++) {
????????????a[n-1-i] = i+1;
????????????b[n-1-i] = i+1;
????????}
??
??
??
????????for(i = 0; i < r; i++) {
????????????scanf("%d %d",&p,&c);
??
????????????for(j = 0; j<c;j++) {
????????a[j] = b[p+j-1];
????????//printf("a[%d] = %d\n",j,a[j]);
????????????}
????????????for(j = 0;j<p-1;j++) {
????????a[c+j] = b[j];
????????//printf("a[%d] = %d\n" ,c+j ,a[c+j]);
????????????}
??
????????????for(j = 0;j<p+c-1;j++) {
????????b[j] = a[j];
????????????}
????????}
??
??
????????printf("%d\n",a[0]);
??
????}
??
????return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <stack>

using namespace std;

int main(){
	int n, r;
	while(cin >> n >> r, n || r){
		int p, c;
		stack<int> S,P,C;
		for(int i = 1; i <= n; i++){
			S.push(i);
		}
		while(r){
			cin >> p >> c;
			while(--p){
				P.push(S.top());
				S.pop();
			}
			while(c){
				C.push(S.top());
				S.pop();
				c--;
			}
			while(!P.empty()){
				S.push(P.top());
				P.pop();
			}
			while(!C.empty()){
				S.push(C.top());
				C.pop();
			}
			r--;
		}
		cout << S.top() << "\n";
	}
	return 0;
}

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

void cut(std::vector<int>&v, int p, int c){

	std::vector<int>vv(c);

	for (int i = 0, j = p - 1; i < vv.size(); i++, j++){
		vv[i] = v[j];
	}

	for (int i = p - 2; i >= 0; i--){
		v[i + c] = v[i];
	}

	for (int i = 0; i < c; i++){
		v[i] = vv[i];
	}

}

int main(){

	int n, r;

	while (std::cin >> n >> r){
		if (n == 0 && r == 0)break;
		std::vector<int>v(n);

		for (int i = v.size() - 1; i >= 0; i--)v[i] = v.size() - i;

		for (int i = 0; i < r; i++){
			int p, c;
			std::cin >> p >> c;
			cut(v, p, c);
		}

		std::cout << v[0] << std::endl;

	}
	return 0;
}

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n, r;
vector<int> p, c;
void ops(vector<int> &card, int p, int c) {
    auto tmp = card;
    rep(i, c) {
        card[i] = tmp[i + p - 1];
    }
    rep(i, p) {
        card[i + c] = tmp[i];
    }
}
void solve() {
    vector<int> card(n);
    rep(i, n) card[i] = n - i;
    rep(i, n) cout << card[i] << " ";
    cout << endl;
    rep(i, r) {
        ops(card, p[i], c[i]);
        // rep(i, n) cout << card[i] << " ";
        // cout << endl;
    }
    cout << card[0] << endl;
}
int main() {
    while (cin >> n >> r, n) {
        p.resize(r);
        c.resize(r);
        rep(i, r) cin >> p[i] >> c[i];
        solve();
    }

    return 0;
}

C++: #include <iostream>

#define rep(i, m) for(int i=0; i<m; i++)

int main(void){

	int n, r;		//山の枚数、回数

	while(std::cin >> n >> r, n || r){		//n,rを取得０、０でなければループ

		int n1[51];	//山
		rep(i,n){
			n1[i] = n-i;						//n1[n] = {n,n-1,n-2,.........,1}
		}

		rep(i,r){

			int p, c;		//上からの何枚目、枚数
			int temp[51];	//一時的に保存しておく

			std::cin >> p >> c;				//p,cを取得
			rep(i, c){
				temp[i] = n1[p-1+i];
			}
			rep(i, p-1){
				n1[p-1-i+c] = n1[p-1-i];
			}

			rep(i,c){
				n1[i] = temp[i];
			}
		}
		std::cout << n1[0] << std::endl;
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
    int n,r;

    while (cin>>n>>r && n>0 && r>0){
        int list[50];

        for (int j = 0; j < n; ++j) {
            list[j]=n-j;
        }
        for (int i = 0; i < r; ++i) {
            int p,c;
            int tmp[50];

            cin>>p>>c;
            for (int j = 0; j < c; ++j) {
                tmp[j]=list[p+j-1];
            }
            for (int k = 0; k < p-1; ++k) {
                list[p+c-k-2]=list[p-k-2];
            }
            for (int l = 0; l < c; ++l) {
                list[l]=tmp[l];
            }
        }
        cout<<list[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){
    //?±±??????????????????                                                            
    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];
  }
  cout << endl;
}

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



int main(){
	queue<int> ans,tmp,tmp2;
	int n,r;
	while(cin>>n>>r,n||r){
		for(int i=0;i<n;i++){
			ans.push(n-i);
		}
		int p,c;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			for(int j=0;j<n;j++){
				if(j<p-1){
					tmp.push(ans.front());ans.pop();
				}else if(j<p+c-1){ 
					tmp2.push(ans.front());ans.pop();
				}else{
					tmp.push(ans.front());ans.pop();
				}
			}
			while(tmp2.empty()!=true){
				ans.push(tmp2.front());tmp2.pop();
			}
			while(tmp.empty()!=true){
				ans.push(tmp.front());tmp.pop();
			}
		}
		cout<<ans.front()<<endl;
		while(ans.empty()!=true){
			//cout<<ans.front();
			ans.pop();
		}
	}
	return 0;
}

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

using namespace std;

vector<int> card;
void shuffle(int p, int c) {
	vector<int> buf(c);

	--p;
	for (int i = 0; i < c; ++i) {
		buf[i] = card[p+i];
	}
	for (int i = p-1; i >= 0; --i) {
		card[c+i] = card[i];
	}
	for (int i = 0; i < c; ++i) {
		card[i] = buf[i];
	}
}
void print() {
	for (int i = 0; i < card.size(); ++i) {
		cout << card[i] << " ";
	}
	cout << endl;
}

int main() {
	int n, r;
	while ( cin >> n >> r, n || r ) {
		card.clear();
		card.resize(n);
		for (int i = 0; i < n; ++i) {
			card[i] = i;
		}
		for (int i = 0; i < r; ++i) {
			int p, c; cin >> p >> c;
			shuffle(p, c);
		}
		cout << n-card[0] << endl;
	}
}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
	int card[50][50]={0};
	int mem[50]={0};
	int n;
	int r;
	int k = 0 ;
	int p,c;
	while(1){
		cin >>n >>r;
		if ((n==0)&&(r==0)) break;
		for(int i =0;i<n;i++){
			card[k][i]=i;
		}	
		for (int j=0;j<r;j++){
			cin >> p >> c ;
			for(int l=0;l<n;l++){
				mem[l]=card[k][l];
			}
			for(int m=0;m<p-1;m++){
				card[k][n-p-c+1+m]=mem[n-p+1+m];
			}
			for(int l=0;l<c;l++){
				card[k][n-c+1+l]=mem[n-p-c+2];
			}
		}
		cout << card[k][n-1] <<endl;
		k++;

	}
	
	return 0;
}