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() {
	cin.tie(); ios::sync_with_stdio(false);
	int n, r;
	while (true) {
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		vector<int> card(n);
		iota(card.rbegin(), card.rend(), 1);

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

C++: #include <bits/stdc++.h>
using namespace std;
int A[100], B[100], C[100];

int main() {
    int n, r;
    while(cin >> n >> r) {
        if(n == 0 && r == 0) break;
        for(int i=0; i<n; ++i) A[i] = i;
        while(r--) {
            int p, c; cin >> p >> c;
            for(int i=n+1-p-c; i<n+1-p; ++i) B[i] = A[i];
            for(int i=n+1-p; i<n; ++i) C[i] = A[i];
            for(int i=n+1-p; i<n; ++i) A[i - c] = C[i];
            for(int i=n+1-p-c; i<n+1-p; ++i) A[i + p - 1] = B[i];
        }
        cout << A[n - 1] + 1 << '\n';
    }
}

C++: #include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, r;
    while (1)
    {
        cin >> n >> r;
        if (n == 0 && r == 0)
            break;
        vector<int> v(n);
        rep(i, n) v[i] = n - i;
        rep(i, r)
        {
            int p, c;
            cin >> p >> c;
            vector<int> tmp1(p - 1), tmp2(c);
            rep(i, p - 1) tmp1[i] = v[i];
            for (int i = p - 1; i < p + c - 1; i++)
                tmp2[i - p + 1] = v[i];
            for (int i = 0; i < c; i++)
                v[i] = tmp2[i];
            for (int i = c; i < c + p - 1; i++)
                v[i] = tmp1[i - c];
        }
        cout << v[0] << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
  int n,r,p,c;
  vector<int> ans;
  while(cin >> n,n){
    cin >> r;
    vector<int> v,q;
    for(int i = n;i > 0;i--)v.push_back(i);
    for(int i = 0;i < r;i++){
      cin >> p >> c;
      for(int j = 0;j < p - 1;j++)q.push_back(v[j]);
      for(int j = p - 1;j < p + c - 1;j++)v[j - p + 1] = v[j];
      for(int j = c;j < p + c - 1;j++)v[j] = q[j - c];
    }
    ans.push_back(v[0]);
  }
  for(int i = 0;i < ans.size();i++)cout << ans[i] << endl;
}

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 <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
const double PI=acos(-1.0);
//---------------------------------------------------------------------------//
int n,r,p1,c;
int huda[51],huda2[51];
int main(){
        while(1) {
                cin>>n>>r;
                if(n==0 && r==0) {
                        return 0;
                }
                for(int i=0; i<n; i++) {
                        huda[i]=n-i;
                        huda2[i]=huda[i];
                }
                for(int i=0; i<r; i++) {
                        cin>>p1>>c;
                        for(int j=0; j<c; j++) {
                                huda[j]=huda[p1-1+j];
                        }
                        for(int j=0; j<p1-1; j++) {
                                huda[c+j]=huda2[j];
                        }
                        for(int j=0; j<51; j++) {
                                huda2[j]=huda[j];
                        }
                }
                cout<<huda[0]<<endl;
        }
}

C++: #include <iostream>
using namespace std;
void getcard(int *card, int n);
void shuffle(int *card, int p, int c);
int main(){
  int n,r;
  while (cin>>n>>r,n|r!=0){
    int card[n+1];
    getcard(card,n);
    for (int i=0;i<r;i++){
      int p,c;
      cin>>p>>c;
      shuffle(card,p,c);
    }
    cout<<card[1]<<endl;
  }
}
void getcard(int *card, int n){
  for (int i=1;i<=n;i++){
    card[i]=n+1-i;
  }
}
void shuffle(int *card, int p, int c){
  int temp[p-1];
  for (int i=0;i<p-1;i++){
    temp[i]=card[i+1];
  }
  for (int i=p;i<p+c;i++){
    card[i-p+1]=card[i];
  }
  for (int i=c+1;i<=c+p-1;i++){
    card[i]=temp[i-c-1];
  }
}

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

int main(){
    while(true){
        int n,r;
        cin >> n >> r;
        if(n==0)break;
        vector<int> card(n);
        for(int i=0;i<n;i++){
            card[i]=i+1;
        }
        for(int i=0;i<r;i++){
            int p,c;
            cin >> p >> c;
            int pos=n-p-c+1;
            queue<int> temp;
            for(int j=0;j<c;j++){
                temp.push(card[pos]);
                card.erase(card.begin()+pos);
            }
            while(!temp.empty()){
                card.push_back(temp.front());
                temp.pop();
            }
        }
        cout << card[n-1] << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,r,p,c;
	while(1){
		cin>>n>>r;
		if(n==0 && r==0)break;
		int dt[n];
		int alt[n];
		rep(i,n)alt[i]=0;
		for(int i=n;i>0;i--){
			dt[n-i]=i;
			alt[i-1]=0;
		}
		rep(j,r){
			cin>>p>>c;
			loop(i,p+c-1,n)alt[i]=dt[i];
			rep(i,p-1)alt[c+i]=dt[i];
			loop(i,p-1,p+c-1)alt[i-p+1]=dt[i];
			rep(i,n)dt[i]=alt[i];
		}
		cout<<dt[0]<<endl;
	}
	return 0;
}