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++: #pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    int n,r;
  while(1){
   cin>>n>>r;
   if(n==0||r==0)return 0;
   V<int> a(n);
   for(int i=0;i<n;i++)a[i]=i+1;
   reverse(all(a));
   int p,c;
   for(int i=0;i<r;i++){
       V<bool> used(n,false);
       V<int> tmp;
       cin>>p>>c;
       for(int j=p-1;j<p+c-1;j++){
            tmp.push_back(a[j]);
            used[j]=true;
       }
       for(int j=0;j<n;j++)if(!used[j])tmp.push_back(a[j]);
       a=tmp;
   }
   cout<<a[0]<<endl;
  }
}

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

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

const int N = 50;
int d[N], t[N];

int main(){
	int n, r, p, c;
	while(cin >> n >> r, n){
		for(int i = 0;i < n;++i){
			d[i] = n - i;
			t[i] = 0;
		}
		for(int i = 0;i < r;++i){
			cin >> p >> c;
			for(int j = 0;j < n;++j){
				if(j < c){
					t[j] = d[p - 1 + j];
				}
				else if(j < p - 1 + c){
					t[j] = d[j - c];
				}
				else{
					t[j] = d[j];
				}
			}
			for(int j = 0;j < n;++j){
				d[j] = t[j];
				t[j] = 0;
			}
		}
		cout << d[0] << endl;
	}
	return 0;
}

C++: #include <iostream>

#define rep(i, m) for(int i=0; i<m; i++)

int main(void){

	int n, r;		//山の枚数、回数
	int p, c;		//上からの何枚目、枚数
	int n1[50];	//山
	int temp[50];	//一時的に保存しておく
	int ans[50];	//答えを保存しておく
	int j=0;		//答えを格納する時に使う

	while(std::cin >> n >> r, n || r){		//n,rを取得０、０でなければループ

		rep(i,n){
			n1[i] = n-i;						//n1[n] = {n,n-1,n-2,.........,1}
		}

		rep(i,r){

			std::cin >> p >> c;				//p,cを取得
			rep(i, c){
				temp[i] = n1[p-1+i];
			}
			rep(i, p-1){
				n1[p-1-i+c] = n1[p-1-i];
			}

			rep(i,c){
				n1[i] = temp[i];
			}
		}
		ans[j++] = n1[0];
	}

	rep(i,j){
		std::cout << ans[i] << std::endl;
	}

	return 0;
}

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

int main(int argc, char const* argv[])
{
  while (true) {
    int n, r;
    std::cin >> n >> r;
    if (n == 0 && r == 0) {
      break;
    }
    std::vector<int> deck(n);
    for (int i = 0; i < n; ++i) {
      deck[i] = n - i;
    }
    for (int i = 0; i < r; ++i) {
      int p, c;
      std::cin >> p >> c;
      std::vector<int> tmp(c);
      for (int j = 0; j < c; ++j) {
        int x = deck[p - 1];
        deck.erase(deck.begin() + p - 1);
        tmp[j] = x;
      }
      deck.insert(deck.begin(), tmp.begin(), tmp.end());
    }
    std::cout << deck[0] << std::endl;
  }
  return 0;
}

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

int main(){
    int n, r;
    while(cin >> n >> r, n+r){
        int arr[n];
        for(int i = 0; i < n; i++)  arr[i] = n-i;
        int p, c;
        for(int i = 0; i < r; i++){
            cin >> p >> c;
            int next[n], pos = 0;
            for(int j = p-1; j < p-1+c; j++)  next[pos++] = arr[j];
            for(int j = 0; j < p-1; j++)    next[pos++] = arr[j];
            for(int j = p-1+c; j < n; j++)    next[pos++] = arr[j];
            copy(next, next+n, arr);
        }
        cout << arr[0] << endl;
    }
    return 0;
}

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

int main(){
	int n,r,p,c;
	while(cin >> n >> r, n+r){
		int huda[50], tmp[50];
		for(int i=0; i<n; i++){
			huda[i]	= n-i;
			tmp[i] = n-1;
		}
		for(int i=0; i<r; i++){
			cin >> p >> c;
			for(int j=0; j < p+c-1; j++){
				if(j<p-1){
					tmp[j+c] = huda[j];
				}else{
					tmp[j-p+1] = huda[j];
				}
			}
			for(int j=0; j<n; j++){
				huda[j] = tmp[j];	
			}
		}
		cout << huda[0] << "\n";
	}
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(c) (c).begin(),(c).end()
int main(){
	while(true){
		int n,r,a[50]={},b[50]={};
		cin >> n >> r;
		if(n==0) break;
		rep(i,n) a[i]=n-i;
		rep(i,r){
			int p,c;
			cin >> p >> c;
			rotate(a,a+p-1,a+p+c-1);
		}
		cout << a[0] << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


int main(void){
	int ans[1000],cnt=0;
	while(1){
		int n,r;
		cin>>n>>r;
		if(n==0)break;
		int p[50],c[50];
		irep(i,r)cin>>p[i]>>c[i];//?????????????????????
		int pos=0;
		rep(i,r){
			if(pos<c[i]){
				pos+=p[i]-1;
			}else if(pos<c[i]+p[i]-1){
				pos-=c[i];
			}
		}
		ans[cnt]=n-pos;
		cnt++;
	}
	rep(i,cnt)cout<<ans[i]<<endl;
	return 0;
}

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

using namespace std;

int main(){
  int n, r;
  vector<int> card;
  card.reserve(100);
  while(true){
    cin >> n >> r;
    if(!n && !r) break;
    card.clear();
    // 1 .. n
    for(int i = 1; i <=n ; i++){
      card.push_back(i);
    }

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

      cin >> p >> c;
      if(n == c) continue;
      
      vector<int>::iterator it = card.end() - p - c + 1;
      
      // temp
      for(int j = 0; j < c; j++){
        card.push_back(*it);
        it++;
      }
      //erase
      card.erase(it  - c, it);
      
      /*
        it = card.begin();
        while(it != card.end()){
        cout << " " << *it;
        it++;
        }
        cout << endl;
      */
    }
    cout << card[n-1] << endl;
  }
  return 0;
}