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, c, p, i, j, k,count=0, yama[50], hikae[50],ans[50];
		while (1)
		{
			cin >> n >> r;
			if (n == 0)
				break;
			for (i = 0; i < n; i++)
			{
				yama[i] = i + 1;
			}
			for (i = 0; i < r; i++)
			{
				cin >> p >> c;
				for (j = 0; j < n - p - c + 1; j++)
					hikae[j] = yama[j];
				for (k = 0; k < c; k++)
					hikae[n - k - 1] = yama[n - p - k];
				for (k = 0; k < p - 1; k++)
					hikae[n - c - k - 1] = yama[n - k - 1];
				for (j = 0; j < n; j++)
					yama[j] = hikae[j];
			}
			ans[count] = yama[n - 1];
			count++;
		}
		for (i = 0; i < count; i++)
			cout << ans[i] << endl;
	return 0;
}

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

int main(){
  int n,k;
  while(1){
    cin >> n >> k;
    if(n==0&&k==0) break;
    vector<int> card(n+1,0);
    for(int i=1;i<n+1;++i) card[i]=n-i+1;

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

    for(int i=0;i<k;++i){
      int p,c;
      cin >> p >> c;
      rotate(card.begin()+1,card.begin()+p,card.begin()+p+c);
      for(int j=1;j<n+1;++j){
	//cout << card[j] << endl;
      }
    }
    cout << card[1] << endl;
  }
}

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

int main(){
  int n,r;
  stack<int> sp;
  stack<int> cp;
  list<int> m;
  while(cin>>n>>r,n|r){
    for(int i=1;i<=n;i++){
      m.push_back(i);
    }
    int p,c;
    while(r--){
      cin>>p>>c;
      for(int i=0;i<p-1;i++){
       	sp.push(m.back());
	m.pop_back();
      }
      for(int i=0;i<c;i++){
	cp.push(m.back());
	m.pop_back();
      }
      for(int i=0;i<p-1;i++){
       	m.push_back(sp.top());
	sp.pop();
      }
      for(int i=0;i<c;i++){
       	m.push_back(cp.top());
	cp.pop();
      }
    }
    cout<<m.back()<<endl;
  }
}

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int n,r;
	while(true){
		cin >> n >> r;
		if(!n&&!r) break;
		vector<int> fuda;
		REP(i,n) fuda.push_back(i+1);
		REP(i,r){
			int p, c;
			cin >> p >> c;
			for(int j=c-1;j>=0;j--){
				fuda.push_back(fuda[n-p-j]);
			}
			REP(i,c)fuda.erase(fuda.begin()+n-p-i);
		}
		cout << fuda[n] << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()

using namespace std;

const int INF = 1000000000;
const double eps = 1e-8;

int main(void) {
  while(1){
    int n,r;cin>>n>>r;
    if(!(n||r))break;
    vector<int> a(n);
    iota(a.rbegin(),a.rend(),1);
    REP(i,r){
      int p,c;cin>>p>>c;
      vector<int> t(n);
      REP(j,c)t[j]=a[j+p-1];
      REP(j,p-1)t[j+c]=a[j];
      FOR(j,c+p-1,n)t[j]=a[j];
      swap(a,t);
    }
    cout<<a[0]<<endl;
  }
  return 0;
}

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

using namespace std;

void shuffle(int *cards,int p, int c){
	int *mt1 = new int[p-1];
	for(int i=0;i<p-1;i++){
		mt1[i] = cards[i];
	}	
	int *mt2 = new int[c];
	for(int i=0;i<c;i++){
		mt2[i] = cards[p-1+i];
	}
	for(int i=0;i<c;i++){
		cards[i] = mt2[i];
	}
	for(int i=0;i<p-1;i++){
		cards[c+i] = mt1[i];
	}
	delete[] mt1;
	delete[] mt2;
}

int main(){
	int n,r;//カードの枚数,シャッフルの回数
	while(true){
		cin >> n >> r;
		if(n==0 && r==0){
			break;
		}
		int *cards = new int[n];
		for(int i=0;i<n;i++){
			cards[i] = n-i;
		}
		for(int i=0;i<r;i++){
			int p,c;//上からpの場所からc個
			cin >> p >> c;
			shuffle(cards,p,c);
		}
		int result = cards[0];
		cout << result << endl;
		delete[] cards;
	}
	
	return 0;
}

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

int main(){
	int n,r,p,c;
	int a[50],buf[50];
	while(cin>>n>>r,n|r){
		for(int i=0;i<n;i++)a[i]=n-i;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			p--;
			memcpy(buf,a,p*sizeof(int));
			memmove(a,a+p,c*sizeof(int));
			memcpy(a+c,buf,p*sizeof(int));
		}
		cout<<a[0]<<endl;
	}
	return 0;
}

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

int main(){
    int n,r;
    while(cin>>n>>r){
        if(n==0 and r==0) return 0;
        vector<int> card(n);
        for(int i=0;i<n;i++) card[i] = n-i;
        for(int count=0;count<r;count++){
            int p,c;cin>>p>>c;
            p--;
            //card[p] ... card[p+c-1]????????????????????£?????????
            vector<int> tmp(c);
            for(int i=0;i<c;i++) tmp[i] = card[p+i];

            vector<int> cash;
            for(int i=0;i<c;i++) cash.push_back(tmp[i]);
            for(int i=0;i<p;i++) cash.push_back(card[i]);
            for(int i=p+c;i<n;i++) cash.push_back(card[i]);
            card = cash;
        }
        cout << card[0] << endl;
    }
}

C++: #include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000



int main(){
  int card[50];
  int tmp[50];

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

    rep(i,n) card[i]=n-i;

    rep(i,r){
      int p,c;
      scanf("%d %d", &p, &c);
      p--;

      rep(j,c){
	tmp[j]=card[p+j];
      }
      rep(j,p){
	card[c+p-j-1] = card[p-j-1];
      }
      rep(j,c){
	card[j]=tmp[j];
      }
    }

    cout << card[0] << endl;

  }

}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a ; i<b ; i++)
#define dump(x) cout << #x << " = " << x << endl

using namespace std;

int card[50];
int n, r;

void disp(){
	rep(i,0,n) cout << card[i] << " ";
	cout << endl;
	return ;
}

int main(){

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

		rep(i,0,n) card[i] = n - i;
		disp();

		rep(i,0,r){
			int p, c;
			cin >> p >> c;
			int temp[p];

			rep(i,0,p-1) temp[i] = card[i];
			rep(i,0,c) card[i] = card[p-1+i];
			rep(i,0,p-1) card[c+i] = temp[i];

			// disp();

		}

		cout << card[0] << endl;

	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int card[50];
int buffer[50];
int main()
{
	int n,r;
	while(cin>>n>>r,n!=0){
		for(int i=0;i<n;i++)card[i]=n-i;
		for(int i=0;i<r;i++){
			int p,c;
			cin>>p>>c;
			for(int j=0;j<p-1;j++)
				buffer[j]=card[j];
			for(int j=0;j<c;j++)
				card[j]=card[j+p-1];
			for(int j=0;j<p-1;j++)
				card[j+c]=buffer[j];
		}
		cout<<card[0]<<endl;
	}
	return 0;
}