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;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int32 n, r;
	while(cin >> n >> r && n && r){
		vector<int32> x(n);
		REP(i, n) x[i] = i;
		REP(i, r){
			int32 p, c;
			cin >> p >> c;
			p--;
			vector<int32> nx(n);
			REP(j, n){
				if(x[j] < p) nx[j] = x[j]+c;
				else if(x[j] < p+c) nx[j] = x[j]-p;
				else nx[j] = x[j]; 
			}
			swap(nx, x);
		}
		int32 res = 0;
		REP(i, n) if(x[i] == 0) res = n-i;
		cout << res << endl;
	}
}

C++: #include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int n, r;
  while (cin >> n >> r && n && r) {
    vector<int> card(n);
    vector<int> tmp(n);

    REP(i, n) card[i] = n - i;
    REP(i, r) {
      int p, c;
      cin >> p >> c;
      REP(j, n) tmp[j] = card[j];
      REP(j, c) tmp[j] = card[p - 1 + j];
      REP(j, p - 1) tmp[c + j] = card[j];
      REP(j, n) card[j] = tmp[j];
    }
    cout << card[0] << endl;
  }
  return 0;
}

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

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(itr,data) for(__typeof((data).begin()) itr=(data).begin();itr!=(data).end();++itr)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long UInt64;
typedef long long Int64;

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

typedef pair<int ,int > P;

int n,r;

void solve() {
    int ary[60]={};
    rep(i,n+1) ary[i]=n-i+1;

    rep(i,r) {
        int p,c;
        cin>>p>>c;
        p--;
        int tmp[60]={};
        for(int j=1;j<=p;j++) tmp[j]=ary[j];
        for(int j=1;j<=c;j++) swap(ary[j],ary[j+p]);
        for(int j=c+1;j<=c+p;j++) ary[j]=tmp[j-c];
    }
    cout<<ary[1]<<endl;
}

int main() {
    while(cin>>n>>r) {
        if(!(n+r)) return 0;
        solve();
    }
    return 0;
}

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

int main(){

  int N,n,p,c,t;
  int a[51],b[51];
  while(1){
  cin>>N>>n;
  if(N+n==0) break;
  for(int i=1;i<=N;i++){
    a[i]=N+1-i;
    b[i]=N+1-i;
  }

  for(int i=1;i<=n;i++){
    cin>>p>>c;
    t=1;
    for(int j=p;j<p+c;j++){
      b[t]=a[j];
      t++;
    }
      for(int s=1;s<p;s++){
	b[t]=a[s];
	t++;
      }
      for(int w=1;w<=N;w++){
	a[w]=b[w];
      }  
  }

  cout<<b[1]<<endl;
  }
  return 0;
}

C++: #include<iostream>

void showDeck(int *a,int l){
	std::cout << "[";
	for(int i=0;i<l;i++){
		std::cout << a[i] ;
		if(i!=l-1) std::cout << ", ";
	}
	std::cout << "]" << std::endl;
}
int main(void) {
	int n,r;
	int p,c;
	int a[2];
	while(true){
		std::cin >> n;
		std::cin >> r;
		if(n == 0 || r == 0) break;
		int deck[n];
		for(int i=0;i<n;i++){
			deck[i] = n-i;
		}
		for(int ii=0;ii<r;ii++){
			std::cin >> p;
			std::cin >> c;
			int set1[p-1];
			int set2[c];
			for(int i=0; i<p-1;i++){
				set1[i]=deck[i];
			}
			for(int i=0; i<c;i++){
				set2[i]=deck[p-1+i];
			}
			// showDeck(deck,n);
			// showDeck(set1,p-1);
			// showDeck(set2,c);
			for(int i=0;i<c;i++){
				deck[i]=set2[i];
			}
			for(int i=0;i<p-1;i++){
				deck[c+i]=set1[i];
			}
			// showDeck(deck,n);
		}
		std::cout << deck[0] << std::endl;
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 52;
int before[MAXN], after[MAXN];

int main()
{
    int n, r, p, c;
    while(cin >> n >> r && (n && r))
    {
        for(int i = n; i > 0;i--) before[n - i] = i;

        REP(r)
        {
            cin >> p >> c;

            rep(j, p - 1) after[c + j] = before[j];
            rep(j, c) after[j] = before[p - 1 + j];
            rep(j,MAXN) before[j] = after[j];
        }
        cout << before[0] << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main()
{
    while(true){
        int n,r;
        cin >> n >> r;
        if(n == 0 && r == 0) break;
        int tmp[n];
        for(int i = 0; i < n; i++){
            tmp[i] = n-i;
        }
        for(int j = 0; j < r; j++){
            int v[n];
            int p,c; cin >> p >> c;
            for(int i = 0; i < c;i++){
                v[i] = tmp[i+p-1];
            }
            for(int i = 0; i < p-1;i++){
                v[i+c] = tmp[i];
            }
            for(int i = p+c-1; i<n; i++){
                v[i] = tmp[i];
            }
            for(int i = 0; i < n; i++){
                tmp[i] = v[i];
            }
        }
        cout << tmp[0] << endl;
    }
}

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;
    }
}