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 main(){
        int n,r;
        cin >> n >> r; 
        while(n){
                int in[50][2];
                for(int i = 0; i < r; i++){
                        cin >> in[i][0] >> in[i][1];
                }  
                int m = n; 
                for(int i = r-1; i >= 0; i--){
                        int p = in[i][0];
                        int c = in[i][1];
                        if(n-p-c+1 > m) continue;
                        if(n-c < m){
                                m -= p-1;
                        }else{
                                m += c; 
                        }  
                }  
                cout << m << endl;
                cin >> n >> r; 
        }  
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,r,d[55],cp[55],p,c;
	while(cin>>n>>r){
		if(n==0 && r==0)break;
		for(int i=1;i<=n;i++){
			d[i]=n-i+1;
		}
		for(int i=0;i<r;i++){
			cin>>p>>c;
			for(int j=1;j<=p-1;j++){
				cp[j]=d[j];
			}
			for(int j=1;j<=c;j++){
				d[j]=d[p+j-1];
			}
			for(int j=1;j<=p-1;j++){
				d[c+j]=cp[j];
			}
		}
		cout<<d[1]<<endl;

	}
	return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>

#pragma warning( disable: 4996 )

using namespace std;

typedef long long ll;

#define INF 100000000
#define EPS 1e-9

#define MAX_N 50
#define MAX_R 50

int n, r;
int p[MAX_R];
int c[MAX_R];
vector<int> ans_list;

int main(){
	
	while (true){
	
		cin >> n >> r;

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

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

		int ans[MAX_N];
		for (int i = 0; i < n; i++){
			ans[i] = n - i;
		}
		int tmp[MAX_N];

		for (int i = 0; i < r; i++){
			
			for (int j = 0; j < c[i]; j++){
				tmp[j] = ans[p[i] - 1 + j];
			}

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

			for (int j = 0; j < c[i]; j++){
				ans[j] = tmp[j];
			}

		}

		ans_list.push_back(ans[0]);
	
	}

	for (int i = 0; i < ans_list.size(); i++){
		cout << ans_list[i] << endl;
	}


	return 0;

}

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

int main()
{
	int n, r;
	while (scanf("%d %d", &n, &r), n + r){
		vector<int> a;
		for (int i = n; i >= 1; i--){
			a.PB(i);
		}
		for (int i = 0; i < r; i++){
			int p, c;
			scanf("%d %d", &p, &c);
			vector<int> b;
			for (int i = p - 1; i < p + c - 1; i++){
				b.PB(a[i]);
			}
			for (int i = 0; i < p - 1; i++){
				b.PB(a[i]);
			}
			for (int i = p + c - 1; i < n; i++){
				b.PB(a[i]);
			}
			a = b;
		}
		printf("%d\n", a[0]);
	}
	
	return 0;
}

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

int main(){
	while (true){
		int n, r,a[50];
		cin >> n >> r;
		if (n == 0 && r == 0){ break; }
		for (int i = 0; i < n; i++){
			a[i] = n-i;
		}

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

		cout << a[0] << endl;
	}
	return 0;
}

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

int main(){
    int n,r;
    for(;;){
        scanf("%d%d",&n,&r);
        if(n==0 && r==0) break;
        int p,c;
        vector<int> ca(n);
        for(int i=0;i<n;i++){
            ca[i]=n-i;
        }
        for(int i=0;i<r;i++){
            scanf("%d%d",&p,&c);
            rotate(begin(ca),begin(ca)+p-1,begin(ca)+p-1+c);
        }
        printf("%d\n",ca[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,p,c;
    vi v(51,0);
    vi t(51,0);
    while(cin >> n >> r,n != 0) {
        rep(i,n) v[i] = n - i;
        rep(i,r){
            cin >> p >> c;
            rep(j,c) t[j] = v[p - 1 + j];
            rrep(j,p) v[j + c - 1] = v[j - 1];
            rep(j,c) v[j] = t[j];
        }
        cout << v[0] << endl;
    }
    return 0;

}

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

#define R input[0][1]

using namespace std;

int input() {
	int input[51][2];
	cin >> input[0][0] >> input[0][1];								//まずnとr
	if (input[0][0] == 0 && input[0][1] == 0) {
		return 0;
	}
	for (char pos = 1; pos <= input[0][1]; pos++) {					//r回のシャッフルの仕方を入力
		cin >> input[pos][0] >> input[pos][1];
	}																//ここまで入力

	/*シャッフルもどし*/
	int whtop = 1;													//最後一番上にいるカードは、今何番目にいる？
	if (R==0)return input[0][0];									//一回もシャッフルしないならコレ

	whtop = input[input[0][1]][0];									//一回目のもどしだけ別枠
	R--;
	while (input[0][1] != 0) {	
		if (whtop <= input[R][1]) whtop = whtop + input[R][0] - 1;
		else if ((input[R][0] + input[R][1] - 1) < whtop) whtop = whtop;
		else whtop = whtop - input[R][1];
		R--;
	}
	return input[0][0] - whtop + 1;

}


int main()
{
	while (1) {
		int check;
		check = input();
		if (check == 0)break;
		else {
			cout << check << endl;
		}
	}
}

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()
{
	while (1) {
		int check;
		check=input();
		if (check == 0)break;
		else {
			cout << check << endl;
		}
	}

}

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

using namespace std;

int main(){
  int n,r;
  int p,c;
  while(1){
    cin >> n >> r;
    if(n == 0) break;
    vector<int> A(n);
    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;
}