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;

  while(cin >> n >> r && n != 0 && r != 0){
    int card[51],temp[51],p,c;

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

    while(r--){
      cin >> p >> c;
      int i;
      for(i=p;i < p+c;i++){
        temp[i-p+1] = card[i];
      }

      for(i=1;i<p;i++){
        temp[i+c] = card[i];
      }

      for(i=p+c;i < n+1;i++){
        temp[i] = card[i];
      }

      for(i=1;i<n+1;i++){
        card[i] = temp[i];
      }
    }

    cout << card[1] << endl;
  }

  return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
using namespace std;
int x[100];
int y[100];
int card [100];
int n,r;
int ans[1000];
int counter;
bool input(){
    for(int i=0;i<100;i++){
    x[i]=0;
    y[i]=0;
    }
    cin >>n>>r;
    for(int i=0;i<r;i++){
    cin>>x[i]>>y[i];
    }
  if(n==0){
    return false;
    }
    else{
     return true;
    }
}
void solve(){
  for (int i=0;i<100;i++){
    cout<<x[i]<<y[i]<<endl;
  }
    for(int i=0;i<100;i++){
        card[i]=i+1;
    }
    for(int i=0;i<r;i++){
        for(int k=0;k<y[i];k++){
            int a=card[x[i]+y[i]-2];
            for(int j=x[i]+y[i]-1;j>0;j--){
                card[j]=card[j-1];
            }
            card[0]=a;
       
        }
    for(int j=1;j<=y[i]/2;j++){
      int remainder=card[j];
      card[j]=card[y[i]-j];
      card[y[i]-j]=remainder;
}
    }
    cout<<card[0]<<endl;
    ans[counter]=card[0];
    counter+=1;
}
    
    
    
int main (){
counter=0;
    while(input()){
    solve();
    }
for(int j=0;j<=counter;j++){
//cout<<ans[counter]<<endl;
}
return 0;
}

C++: #include <iostream>
using namespace std;
 
int main(){
    while(true){
        int n, r, p, c;
        cin >> n >> r;
        if ((not n) && (not r)) break;
        int card1[n], card2[n];
        for (int i = 0; i < n; ++i){
            card1[i] = n - i;
            card2[i] = n - i;
        }
        for (int i = 0; i < r; ++i){
            cin >> p >> c;
            for (int j = 0; j < n; ++j){
                if (i % 2){
                    if (j < c){
                        card1[j] = card2[p-1+j];
                    }else if(j < c + p - 1){
                        card1[j] = card2[j-c];
                    }else{
                        card1[j] = card2[j];
                    }
                }else{
                    if (j < c){
                        card2[j] = card1[p-1+j];
                    }else if(j < c + p - 1){
                        card2[j] = card1[j-c];
                    }else{
                        card2[j] = card1[j];
                    }
                }
            }
        }
        if (r%2) cout << card2[0] << endl;
        else cout << card1[0] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RFOR(i, a, b) for (int i=a;i>=b;--i)
#define ll long long
#define all(a) a.begin(),a.end()
#define ull unsigned long long
#define pb(x) push_back(x)
#define dbg(x) cout<<#x<<" : "<<(x)<<endl;
using namespace std;
const int INF = 1500000000;
const double PI = 3.14159265359;
const int mod = 1000000000 + 7;

int n, r, p[50], c[50], d[50], tmp[50];

void solve() {
  rep(i, r) {
    rep(j, p[i]-1 + c[i]) tmp[j] = d[j];
    rep(j, c[i]) {
      d[j] = tmp[p[i]-1 + j];
    }
    rep(j, p[i] - 1) {
      d[c[i] + j] = tmp[j];
    }
  }
  printf("%d\n", d[0]);
}

int main() {
  while(true) {
    scanf("%d %d", &n, & r);
    if (!n && !r) break;
    rep(i, n) d[i] = n - i;
    rep(i, r) scanf("%d %d", &p[i], &c[i]);
    solve();
  }
  return 0;
}

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

using namespace std;

int main(void) {
  vector<int> v;
  int n,r;
  int p,c;
  while(true) {
    cin >> n >> r;
    if(n == 0 && r == 0)
      break;
    v.clear();
    for(int i = 0; i < n; i++)
      v.push_back(i + 1);
    for(int i = 0; i < r; i++) {
      cin >> p >> c;
      p -= 1;
      rotate(v.rbegin(), v.rbegin() + p, v.rbegin() + p + c);
    }
    cout << v.back() << endl;
  }
  return 0;
}

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

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

		if (n == 0 && r == 0) {
			break;
		}
		vector<int> cards;
		for (int i = 1; i <= n; i++) {
			cards.push_back(i);
		}

		for (; r > 0; r--) {
			cin >> p >> c;

			p = n - p - c + 1;
			for (; c > 0; c--) {
				cards.push_back(cards[p]);
				cards.erase(cards.begin() + p);
			}
		}
		cout << cards[0] << '\n';
	}
	return 0;
}

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

using namespace std;

int main(){
	vector<int> cards;
	vector<int> ::iterator cardsIterator;
	vector<int> ::iterator shuffuleIterator;
	int n,r,p,c;

	while(cin >> n >> r, n && r){
		cards.clear(); //初期化
		// カードの山生成
		for (int i = 0; i < n; ++i){
			cards.push_back(i+1);
		}
		// シャッフル
		while(cin >> p >> c){
			cardsIterator = cards.end();
			cardsIterator -= p + (c - 1);
			while(c--){
				cards.push_back(*cardsIterator);
				cards.erase(cardsIterator);
			}
			if (r == 0){
				break;
			}
		}
		// 一番上のカード表示
		cout << cards.back() << endl;
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,r,p,c,a[50],b[50];
	while(true){
		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++){
			cin>>p>>c;
			for(int j=0;j<p-1;j++)
				b[j+c]=a[j];
			for(int j=p-1;j<p-1+c;j++)
				b[j-p+1]=a[j];
			for(int j=p-1+c;j<n;j++)
				b[j]=a[j];
			for(int j=0;j<n;j++)
				a[j]=b[j];
		}
		cout<<a[0]<<endl;
	}
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }


int main() {
    int n, r;
    while(1) {
        cin >> n >> r;
        if(n == 0 && r == 0) break;
        stack<int> yama;
        for(int i = 1; i <= n; ++i) yama.push(i);
        stack<int> hako;
        stack<int> ue;
        for(int i = 0; i < r; ++i) {
            int p, c; cin >> p >> c;
            for(int j = 0; j < p-1; ++j) {
                hako.push(yama.top());
                yama.pop();
            }
            for(int j = 0; j < c; ++j) {
                ue.push(yama.top());
                yama.pop();
            }
            while(!hako.empty()) {
                yama.push(hako.top());
                hako.pop();
            }
            while(!ue.empty()) {
                yama.push(ue.top());
                ue.pop();
            }
        }
        cout << yama.top() << endl;
    }
}