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>
using namespace std;

void shuffle( vector <int>& cards, int p, int c )
{
    vector <int> replaced( cards.begin() + p - 1, cards.begin() + p + c - 1 );
    replaced.insert( replaced.end(), cards.begin(), cards.begin() + p - 1 );
    for ( int i = 0; i < p+c-1; i++ ) cards[i] = replaced[i];
}

int main( void )
{
    int n, r, p, c;

    while ( cin >> n >> r && n > 0 && r > 0 )
    {
        vector <int> cards( n );
        for ( int i = 0; i < n; i++ ) cards[i] = n - i;
        for ( int i = 0; i < r; i++ )
        {
            cin >> p >> c;
            shuffle( cards, p, c );
        }
        int answer = cards[0];
        cout << answer << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long int
#define MOD 1000000007
#define pb push_back
#define ub upper_bound
#define lb lower_bound

using namespace std;

int main(){
    int n,r;
    int c[50];
    int cp[50];
    int com1,com2;
    int cnt=0;
    while(1){
        cin >> n >> r;
        for(int i=0;i<50;i++){
            c[i]=n-i;
        }
        if(n==0||r==0){
            break;
        }
        
        for(int i=0;i<r;i++){
            for(int i=0;i<50;i++){
                cp[i]=0;
            }
            cin >> com1 >> com2;
            cnt=0;
            for(int i=com1-1;i<com1-1+com2;i++){
                cp[cnt]=c[i];
                cnt++;
            }
            for(int i=com1-2;i>-1;i--){
                c[i+com2]=c[i];
            }
            for(int i=0;i<com2;i++){
                c[i]=cp[i];
            }
        }
        cout << c[0] << endl;
    }
    return 0;
}

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

typedef long long LL;
#define rep(i ,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define all(v) (v).begin(),(v).end()
#define arycpy(ary1,ary2,N) memcpy(ary2,ary1,sizeof(int)*N) //ary1:???????????? ary2:????????????
typedef vector<int> vi;


int main(){
	while (1){
		int n, r;
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		int *num = new int[n];
		for (int i = 0; i < n; i++){
			num[i] = n-i;
		}
		for (int i = 0; i < r; i++){
			int p, c; cin >> p >> c;
			int *ary = new int[n];
			rep(j, n) ary[j] = 0;

			//????????\????????????(c???)?????£??\
			for (int j = 0; j < c; j++){
				ary[j] = num[p - 1 + j];
			}
			
			//??????????????????????????????(p-1???)?????£??\
			for (int j = c; j <c+p-1; j++){
				ary[j] = num[j - c];
			} 

			//rep(j, n) cout << ary[j] << " ";
			//cout << endl;

			for (int j = p+c-1; j < n; j++){
				ary[j] = num[j];
			}
			arycpy(ary, num, n);
			//rep(j, n) cout << num[j] << " ";
			//cout << endl;
		}
		cout << num[0] << endl;
	}
	return 0;
}

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

int main(void)
{
	int n, r;
	while (cin >> n >> r, n && r){
		vector <int> card, tmp;
		// いちばんさいしょ＝いちばんうえ
		for (int i = n; 0 < i; i--){
			card.push_back(i);
		}
		/*
		for (int i = 0; i < n; i++){
			cout << card[i] << " ";
		}
		puts("");
		*/
		int p, c;
		while (r--){
			cin >> p >> c;
			for (int i = p; i < p+c; i++){
				tmp.push_back(card[i-1]);
			}
			for (int i = 0; i < p-1; i++){
				tmp.push_back(card[i]);
			}
			for (int i = p+c-1; i < n; i++){
				tmp.push_back(card[i]);
			}
			card = tmp;
			/*
			for (int i = 0; i < n; i++){
				cout << card[i] << " ";
			}
			puts("");
			*/
			tmp.clear();
		}
		cout << card[0] << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,R;
  cin >> N >> R;
  while(N != 0){
    string S = "";
    for(int i=N; i>=1; i--){
      S += i + '0';
    }
    for(int i=0; i<R; i++){
      int p,c;
      cin >> p >> c;
      p--;
      S = S.substr(p,c) + S.substr(0,p) + S.substr(p+c);
    }
    cout << S[0]-'0' << endl;
    cin >> N >> R;
  }
  return 0;
}

C++: #include<stdio.h>

int main() {

	int n, r;
	int array[51];
	int tmp[51];
	while (1) {
		scanf("%d %d", &n, &r);
		if (n == 0 && r == 0) break;

		for (int i = 1; i <= n; i++) {
			array[i] = i;
		}
		for (int i = 0; i < r; i++) {
			int p, c;
			scanf("%d %d", &p, &c);
			for (int j = 0; j < c; j++) {
				tmp[j] = array[n - (p - 1) - j];
			}
			for (int j = 0; j < (p - 1); j++) {
				array[n - (p - 1) - c + 1 + j] = array[n - (p - 1) + 1 + j];
			}
			for (int j = 0; j < c; j++) {
				array[n - c + 1 + j] = tmp[c - 1 - j];
			}
		}
		printf("%d", array[n]);
	}
}

C++: #include <iostream>
using namespace std;
int n,r;
int card[50];

void shuffle(int p,int c) {
  int temp[50];
  for(int i=0;i<n;i++) {
    temp[i] = card[i];
  }
  for(int i=0;i<c;i++) {
    card[i] = temp[p-1+i];
  }
  for(int i=c;i<c+p-1;i++) {
    card[i] = temp[i-c];
  }
}

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

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

using namespace std;

int n[1000]={},r[1000]={};
int p[1000][50] = {};
int c[1000][50] = {};
int i=0;

int d[50]={};
int e[50] = {}; //今の状態
int e2[50] = {};

int main(){
    while(1){
        scanf("%d %d",&n[i],&r[i]);
        if(n[i]== 0 && r[i]== 0){
            break;
        }
        for(int j=0;j<r[i];j++){
            scanf("%d %d",&p[i][j],&c[i][j]);
        }
        i++;
    }
    int times = i;
    for(i=0;i<times;i++){
        //初期化
        int s=0;
        for(int k = n[i]; k>0;k--){
            e[s] = k;
            s++;
        }
        for(int j=0;j<r[i];j++){
            s=0;
            for(int t=p[i][j]-1;t<p[i][j]+c[i][j]-1;t++){
                d[s] = e[t];
                s++;
            }
            for(int t = 0;t < n[i];t++){
                e2[t] = e[t];
            }
            for(int t = 0;t<c[i][j];t++){
                e[t] = d[t];
            }
            for(int t=0;t<n[i]-c[i][j];t++){
                e[t+c[i][j]] = e2[t];
            }

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

    return 0;
}