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>
#include <vector>

using namespace std;

int main(){
    while(true){
        int n, r;
        cin >> n >> r;
        if(n==0 && r==0) return 0;
        vector<int> deck(n);

        for(int i=0;i<deck.size();i++){
            deck[i] = deck.size() - i;
        }

        //      for(int k=0;k<n;k++) cerr << deck[k];
//        cerr << endl;

        for(int i=0;i<r;i++){
            int p,c;
            cin >> p >> c;
            vector<int> cdeck = deck;

            for(int j=0;j<c;j++){
                deck[j] = cdeck[p-1+j];
            }

            for(int j=0;j<p-1;j++){
                deck[c+j] = cdeck[j];
            }

            //for(int k=0;k<n;k++) cerr << deck[k];
//            cerr << endl;
        }
        cout << deck[0] << endl;
    }
}

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

int main(){
	int n,r;
	while((cin >> n)&&(cin >> r)&&(n!=0)&&(r!=0)){
		int a[256];
		int cnt=n;
		for(int i=0;i<n;i++){
			a[i] = cnt;
			cnt--;
			//cout << "a[" << i << "]" << a[i] << endl;
		}
		int p,c;
		//cout << endl;
		for(int i=0;i<r;i++){
			cin >> p;
			cin >> c;
			int b[50];
			//cout << p << endl;
			//cout << c << endl;
			//cout << endl;
			if(n!=c){
				for(int j=0;j<p-1;j++){
					b[j+c] = a[j];
				}
				for(int j=0;j<c;j++){
					b[j] = a[p+j-1];	
				}
				for(int j=0;j<p+c-1;j++){
					a[j] = b[j];	
					//cout << "a[" << j << "]" << a[j] << endl;
				//	cout << "b[" << j << "]" << b[j] << endl;
				}
			}
		}
		cout << a[0] << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, r;
    while(cin >> n >> r, n or r)
    {
        vector<int> v(n);
        iota(v.begin(), v.end(), 1);
        for(int i = 0; i < r; i++)
        {
            int p, c; cin >> p >> c;
            vector<int> tmp(v.begin() + n - p - c + 1, v.begin() + n - p + 1);
            v.erase(v.begin() + n - p - c + 1, v.begin() + n - p + 1);
            v.insert(v.end(), tmp.begin(), tmp.end());
        }
        cout << v.back() << endl;
    }
    return 0;
}

C++: #include <stdio.h>

void swap(int n, int p, int c, int* card){
  int *temp1 = new int[p-1];
  int *temp2 = new int[c];
  for(int i=0; i<p-1; i++){
    temp1[p-1-1-i] = card[n-1-i];
  }
  for(int i=0; i<c; i++){
    temp2[c-1-i] = card[n-p-i];
  }
  for(int i=0; i<c; i++){
    card[n-1-i] = temp2[c-1-i];
  }
  for(int i=0; i<p-1; i++){
    card[n-1-c-i] = temp1[p-1-1-i];
  }
  delete[] temp1;
  delete[] temp2;
}

int main(void){
  int n, r, p, c;
  int i;
  int card[50];

  while(1){
    for(i=0;i<50;i++){
      card[i]=i+1;
    }
    scanf("%d%d", &n, &r);
    if(n==0 && r==0){
      break;
    }
    for(i=0;i<r;i++){
      scanf("%d%d", &p, &c);
      swap(n, p, c, card);
    }
    printf("%d\n", card[n-1]);
  }
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main() {
	int n, k, t, m;
	int a[100];
	int b[100];
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;
while(true) {

	scanf("%d %d", &n, &m);
	if (n == 0 && m == 0)return 0;
	f(i, n)a[i] = n - i;
		f(i, m) {
			scanf("%d %d", &x, &y);
			f(i, n)b[i] = a[i];
			f(i, y)b[i] = a[i + x - 1];
			f(i, x - 1)b[y + i] = a[i];
			f(i, n)a[i] = b[i];
		}
		printf("%d\n", a[0]);
	}



	return 0;
}

C++: #include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	while(1){
		ll n,r; cin >> n >> r;
		if(n==0 && r==0) break;
		vl a(n); rep(i,n) a[i] = i+1;
		while(r--){
			ll p,c; cin >> p >> c;
			vl v;
			REP(i,n-p-c+1,n-p+1){
				v.push_back(a[i]);
			}
			a.erase(a.begin()+n-p-c+1,a.begin()+n-p+1);
			for(auto i : v) a.push_back(i);
		}
		cout << a[n-1] << endl;
	}
}

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

int main(){
    int card[51];
    int tmp[50];
    int n,r, from, num;
    int result[50], numres=0;

    while(1){
        cin >> n >> r;
        if(n == 0 && r == 0) break;
        for(int i=1; i<=n; i++){
            card[i]=n-i+1;
        }
        for(int i=0; i<r; i++){
            cin >> from >> num;
            for(int j=0; j<num; j++){
                tmp[j] = card[from+j];
            }
            for(int j=from; j>0; j--){
                card[j+num] = card[j];
            }
            for(int j=0; j<num; j++){
                card[j+1] = tmp[j];
            }
        }
        result[numres] = card[1];
        numres++;
    }

    for(int i=0; i<numres; i++){
        cout << result[i] << endl;
    }
        
    return 0;
}

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

int main() {
int N,R,p,c;
while (cin>>N>>R&&N) { 
	int A[100]={};
	for(int i=0;i<N;i++){
		A[i]=i+1;
	}
	
	for (int i=0; i<R; ++i) {
	cin >> p >> c ;
	rotate(A,A+p,A+p+c);

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