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<bits/stdc++.h>
using namespace std;

int main(){
  int n,r;
  while(cin >> n >> r, n){
    int npos[100];
    for(int i=n-1,j=0;i>=0;i--,j++){
      npos[j] = i+1;
    }
    for(int i=0;i<n;i++){
      cout << npos[i] << endl;
    }
    for(int i=0;i<r;i++){
      int a,b;
      cin >> a >> b;
      int tmp[b];
      for(int j=0;j<b;j++){
	tmp[j] = npos[j+a-1];
      }
      for(int j=a+b-2;j>=b;j--){
	npos[j] = npos[j-b];
      }
      for(int j=0;j<b;j++){
	npos[j] = tmp[j];
      }
      for(int i=0;i<n;i++){
	cout << npos[i] << endl;
      }
    }
    cout << npos[0] << endl;
  }
}

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

int main(void){
	int n,r,c,p,a;
	while(1){
		cin >> n >> r;
		if(!n && !r) break;
		vector<int> d(n);
		for(int i=0;i<n;i++){
			d[i] = n-i;
		}
		for(int i=0;i<r;i++){
			cin >> p >> c;
			for(int j=c; j>0;j--){
				a = d[c+p-2];
				d.erase(d.begin()+c+p-2);
				d.insert(d.begin(),a);


			}
			// for(int j=0;j<n;j++){
			// cout << d[j] << endl;
			// }
		}
		// cout << "answer" << endl;
		// for(int i=0;i<n;i++){
		// 	cout << d[i] << endl;
		// }
		cout << d[0] << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;main(){for(int n,r,p,c;cin>>n>>r,n;){string d;for(int i=0;i<n;i++)d=char(48+i)+d;for(;r;r--){cin>>p>>c;d = d.substr(p-1,c)+d.substr(0,p-1)+d.substr(p+c-1);}cout<<(d[0]-47)<<"\n";}}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
 
using namespace std;

void shuffle(int card[], int p, int c);

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

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

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

int main(){
	while(1){
		int n,r,p,c,s[n + 1];
		cin >> n >> r;
		if(n == 0 && r ==0)break;
		for(int i = 1; i <= n;++i){
			s[i] = i;
			}
			for(int j = 1; j <= r;++j){
				cin >> p >> c;
			    for(int k = 1;k <=c;++k){
			    		s[0] = s[n - p - c + 2];
				    for(int l = 1;l <= p + c - 2;++l){
					    s[n - p - c + 1 + l] = s[n - p - c + 2 + l];
					}
					s[n] = s[0];
			    }
		     }
		  cout << s[n] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
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[100];
	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>
using namespace std;
int main(){
  int n,r,fu[51];
  while(1){
    cin>>n>>r;
    if(n==0&&r==0)break;
    for(int i=1;i<=n;i++)fu[i]=n+1-i;
    for(int j=0;j<r;j++){
      int p,c,cp[50];
      cin>>p>>c;
      for(int k=0;k<c;k++){
	cp[k]=fu[p+k];
	}
      for(int k=p+c-1;k-c>=1;k--){
	fu[k]=fu[k-c];
      } 
      for(int k=1;k<=c;k++){
	fu[k]=cp[k-1];
	}
    }
    cout<<fu[1]<<endl;
  }
  return 0;
}

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

using namespace std;

int main(int argc, char const* argv[])
{
	int n, r, p, c;

	while(true) {
		cin >> n >> r;
		if(n == 0 && r == 0) break;

		vector<int> cards(n);

		for(int i = 0; i < n; ++i) {
			cards.at(n - i - 1) = i + 1;
		}

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

			vector<int> temp_p;
			vector<int> temp_c;

			copy_n(cards.begin(), p - 1, std::back_inserter(temp_p));
			copy_n(cards.begin() + p - 1, c, std::back_inserter(temp_c));

			copy(temp_c.begin(), temp_c.end(), cards.begin());
			copy(temp_p.begin(), temp_p.end(), cards.begin() + c);
		}

		std::cout << cards.at(0) << std::endl;
	}

	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n,r;
	while(cin>>n>>r,r){
		int cards[60],i;
		for(i=0;i<60;i++)cards[i]=i;
		for(i=0;i<r;i++){
			int a,b;
			cin>>a>>b;
			a--;
			int j;
			int c[60];
			for(j=0;j<60;j++){
				if(j<b){
					c[j]=cards[a+j];
				}else if(j<a+b){
					c[j]=cards[j-b];
				}else{
					c[j]=j;
				}
			}
			for(j=0;j<60;j++){
				cards[j]=c[j];
//cout<<cards[j]<<endl;
			}
//cout<<endl;
		}
		cout<<n-cards[0]<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  while(true){
  int n,r,p,c;
  cin>>n>>r;
  if(!n&&!r)break;
  string deck;
  for(int i=0;i<n;i++)
    deck = char(48+i)+deck;
  for(int i=0;i<r;i++){
    cin>>p>>c;
    deck = deck.substr(p-1,c)+deck.substr(0,p-1)+deck.substr(p+c-1);
  }
  cout<<(deck[0]-47)<<endl;
  }
  return 0;
}

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

using namespace std;

int main(){
	int n, r;
	int card[50], shuf[50];
	while(cin >> n >> r){
		if(!n) break;
		for(int i=0;i<n;i++) card[i] = n-i;
		for(int i=0;i<r;i++){
			int p, c; cin >> p >> c;
			int j=0;
			for(j=0;j<c;j++) shuf[j] = card[p-1+j];
			for(j=c;j<c+p-1;j++) shuf[j] = card[j-c];
			for(j=c+p-1;j<n;j++) shuf[j] = card[j];
			memcpy(card,shuf,sizeof(card));
		}
		cout << shuf[0] << endl;
	}
}