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 || R) {
        vector<int> v(N);
        for (int i = 0; i < N; i++) {
            v[i] = i+1;
        }

        while (R--) {
            int p, c;
            cin >> p >> c;
            auto w = v;
            for (int i = 0; i < p-1; i++) {
                w[N - p - c + i + 1] = v[N - p + i + 1];
            }

            for (int i = 0; i < c; i++) {
                w[N - c + i] = v[N - p - c + i + 1];
            }

            v = w;
        }

        for (auto i : v) cout << i << " ";
        cout << endl;

        cout << v[N-1] << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long LL;
typedef vector<int>    VI;
typedef vector<bool>   VB;
typedef vector<string> VS;

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

int n, r;
VI ps, cs;
VI cards;

int main(void) {
	while (1) {
		cards.clear();
		ps.clear();
		cs.clear();
		cin >> n >> r;
		if (n ==  0 && r == 0) break;
		rep (i, n) {
			cards.PB(n - i);
		}
		rep (i, r) {
			int p, c;
			cin >> p >> c;
			ps.PB(p);
			cs.PB(c);
		}
		rep (i, r) {
			VI temp;
			REP (j, ps[i] - 1, ps[i] + cs[i] - 1) {
				temp.PB(cards[j]);
			}
			rep (j, ps[i] - 1) {
				temp.PB(cards[j]);
			}
			REP (j, ps[i] + cs[i] - 1, cards.size()) {
				temp.PB(cards[j]);
			}
			cards = temp;
		}
		cout << cards[0] << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1001

void calc(int n,int r){
  stack<int> card;

  for(int i=0;i<n;i++){
    card.push(i+1);
  }

  for(int i=0;i<r;i++){
    int p,c;
    stack<int> s1,s2;

    scanf("%d%d",&p,&c);

    for(int i=0;i<p-1;i++){
      s1.push(card.top());
      card.pop();
    }

    for(int i=0;i<c;i++){
      s2.push(card.top());
      card.pop();
    }

    for(int i=0;i<p-1;i++){
      card.push(s1.top());
      s1.pop();
    }

    for(int i=0;i<c;i++){
      card.push(s2.top());
      s2.pop();
    }

    
    
  }
  
  printf("%d\n",card.top());

}

int main(){
  int n,r;

  while(1){
    scanf("%d%d",&n,&r);
    if(n==0) break;
    calc(n,r);
  }
  
  return 0;
}

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

using namespace std;

int32_t main()
{
  while(true){
    uint32_t n, r;
    cin >> n >> r;
    if(n == 0) break;

    vector<uint32_t> cards(51, 0);
    for(int32_t i = n-1, j = 1;  i >= 0; i--, j++){
      cards[i] = j;
    }

    for(uint32_t i = 0; i < r; i ++){
      uint32_t p, c;
      cin >> p >> c;
      vector<uint32_t> cs;
      for(uint32_t i = p - 1; i < p - 1 + c; i++){
        cs.push_back(cards[i]);
      }
      for(uint32_t i = 0; i < p - 1; i++){
        cs.push_back(cards[i]);
      }
      for(uint32_t i = p - 1 + c; i < n; i++){
        cs.push_back(cards[i]);
      }

      for(uint32_t i= 0; i < n; i++){
        cout << cs[i] << " ";
        cards[i] = cs[i];
      }
      cout << endl;
    }

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

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>
using namespace std;


int main()
{
	int n, r, p, c, A[51];
	while (true) {
		cin >> n >> r;
		if (n == 0 && r == 0)break;
		else {
			for (int i = 0; i < n; i++)A[i] = n - i;
			for (int i = 0; i < r; i++) {
				cin >> p >> c;
				rotate(A, A + p - 1, A + p + c - 1);
			}
			cout << A[0] << endl;
			for (int i = 0; i < n; i++)A[i] = 0;
		}
	}
	return 0;
}

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

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

        vector<int> array(n, 0);
        vector<int> copy(n, 0);
        for(int i = 0; i < n; i++){
            array[i] = i+1;
        }
        for(int i = 0; i < r; i++){
            int p, c;
            cin >> p >> c;
            
            for(int j = n - p; j > n - p - c; j--){
                copy[j + p - 1] = array[j];
            }
            for(int j = n - p + 1; j < n; j++){
                array[j - c] = array[j];
            }
            for(int j = n - 1; j > n - 1 - c; j--){
                array[j] = copy[j];
            }
            
        }

        cout << array[n-1] << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
const ll mod = 1e9 + 7;

int main() {
	cin.sync_with_stdio(false);
	int n,r;
	vector<int>ans;
	while (1) {
		cin >> n >> r;
		if (n == 0 && r == 0)break;
		vector<int>b(n), a(n);
		int p, c;
		rep(i, n)b[i] = n-i;
		rep(i, r) {
			cin >> p >> c;
			rep(j, c)a[j] = b[p - 1 + j];
			rep(j, p-1)a[c + j] = b[j];
			reps(j, p + c - 1, n)a[j] = b[j];
			rep(j, n)b[j] = a[j];			
		}
		ans.push_back(a[0]);

	}
	for (auto x : ans)cout << x << endl;
	return 0;
}

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

void show(int* x, int n);

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

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

using namespace std;

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

		for (int i = n-1; i>=0 ; i--){
			hanahuda[i]=n-i;
		}
		int top;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			top=top_search(n,p,c,hanahuda);
		}
		cout << top << endl;
		delete[] hanahuda;
	}
	
	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;
}