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 <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int main(void) {
    int n, r;
    while (cin >> n >> r) {
        if (n == 0 && r == 0) break;
        int card[n];
        for (int i = 0; i < n; i++) {
            card[i] = n-i;
        }
        for (int i = 0; i < r; i++) {
            int p, c;
            cin >> p >> c;
            p--;
            int buf[n];
            int ue[n];
            int cur = 0;
            for (int j = 0; j < n; j++) {
                if (j < p || j >= p+c) {
                    buf[cur] = card[j];
                    cur++;
                }
            }
//            for (int j = 0; j < cur; j++) cout << buf[j] << " ";
//            cout << endl;
            for (int j = 0; j < c; j++) {
                ue[j] = card[p+j];
            }
            for (int j = 0; j < c; j++) card[j] = ue[j];
            for (int j = c; j < n; j++) card[j] = buf[j-c];
        }
//        for (int i = 0; i < n; i++) cout << card[i] << " ";
//        cout << endl;
        cout << card[0] << endl;
    }
    return 0;
}

C++: //rotateも何も知らず、また頂いたPDFもまともに読まないまま知っている知識のみで解いた結果です。
//少なくとも提出してAcceptは出ています。
//「きれいなプログラム」がどんなものかまだ把握できていないため、この点に関してもご指摘等頂ければと思います。
//千田 直輝

#include<iostream>

#define R input[0][1]

using namespace std;

int getTop() {
	int input[51][2];

	/*入力*/
	cin >> input[0][0] >> input[0][1];								//まずnとrを受け取る。
	if (input[0][0] == 0 && input[0][1] == 0) {						//n=r=0なら0を返して関数終了。
		return 0;
	}
	for (char pos = 1; pos <= R; pos++) {							//シャッフルの仕方をr回分入力
		cin >> input[pos][0] >> input[pos][1];
	}

	/*シャッフルもどし*/
	int whtop = 1;													//最後一番上にいるカードは、今何番目にいる？
	if (R==0)return input[0][0];									//一回もシャッフルしないならコレ
	while (R != 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 = getTop();
		if (check == 0)break;
		else cout << check << endl;
	}
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n, r;
    while (cin >> n >> r, n) {
        stack<int> st;
        for (int i = 0; i < n; i++) {
            st.push(i + 1);
        }
        int p, c;
        while (r--) {
            cin >> p >> c; p--;
            stack<int> a[2];
            while (p--) { a[0].push(st.top()); st.pop(); }
            while (c--) { a[1].push(st.top()); st.pop(); }
            for (int i = 0; i < 2; i++) {
                while (!a[i].empty()) {
                    st.push(a[i].top());
                    a[i].pop();
                }
            }
        }
        cout << st.top() << endl;
    }
    return 0;
}

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

using namespace std;

int top_search(int,int,int,int *);
int main(){
	int n,r,c,p;
	int cnt=0;
	int top[50];
	while(1){
		cin>>n>>r;
		if(n==0&&r==0)
			break;
		int hanahuda[50];

		for (int i = n-1; i>=0 ; i--)
			hanahuda[i]=n-i;

		for(int i=0;i<r;i++){
			cin>>p>>c;
			top[cnt]=top_search(n,p,c,hanahuda);
		}
		cnt++;
	}
	for(int m=0;m<cnt;m++)
		cout<<top[m]<<endl;
	return 0;
}
int top_search(int n,int p,int c,int *hanahuda){
	int cnt=0;
	for(int k=p-1;k<p+c-1;k++){

		int nokori=hanahuda[k];

		for(int l=p-2;l>=0;l--)
			hanahuda[l+1]=hanahuda[l];


		hanahuda[cnt]=nokori;
		cnt++;
	}

	return *hanahuda;
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,R;
    cin >> N >> R;
    while(N){
        vector<int> V(N);
        iota(V.rbegin(), V.rend(), 1);
        for(auto i:V)cout << i << endl;
        rep(i,0,R){
            int p,c;
            cin >> p >> c;
            p--;
            vector<int> tmp(p + c);
            rep(j,0,c){
                tmp[j] = V[j + p];
            }
            rep(j,c,p+c){
                tmp[j] = V[j-c];
            }
            rep(j,0,p+c){
                V[j] = tmp[j];
            }
        }
        cout << V[0] << endl;
        cin >> N >> R;
    }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

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

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

    vector<int> v(n);
    REP(i,n){
      v[i] = n - i;
    }

    REP(i,r){
      int c, p;
      cin >> p >> c;

      vector<int> tmp(c+p-1);
      REP(i,c+p-1){
        if(i < c){
          tmp[i] = v[i+p-1];  
        }else{
          tmp[i] = v[i-c];
        }

      }
      REP(i,c+p-1){
        v[i] = tmp[i];
      }

    }

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

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

using namespace std;


int main(){

  int n,r,p,c;
  vector<int> y,P,C;

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

    y.clear();
    y.resize(n);
    for(int i=0; i<y.size(); ++i){
      y[i]=i+1;
    }
    
    for(int i=0; i<r; ++i){
      cin >> p >> c;
      
      P.clear();
   #include <bits/stdc++.h>

using namespace std;

   P.resize(y.size()-p);
      C.clear();
      C.resize(c);
      
      for(int k=0; k<P.size(); ++k){
	P[k]=y[k+p];
      }
      
      for(int k=0; k<C.size(); ++k){
	C[k]=y[k+p-c];
      }
#include <bits/stdc++.h>

using namespace std;


      for(int k=0; k<P.size(); ++k){
	y[k+p-c]=P[k];
      }
      
      for(int k=0; k<C.size(); ++k){
	y[y.size()-c]=C[k];
      }

    }

    cout << y[y.size()-1] << endl;
  }

  
  return 0;
}