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;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;} return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;} return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,r;
    while(cin >> n >> r,n,r){
        vector<int> cs(n),cs0(n);
        iota(cs.begin(),cs.end(),1);
        reverse(cs.begin(),cs.end());
        rep(i,r){
            int p,c; cin >> p >> c;
            rep(i,n) cs0[i]=cs[i];
            rep(j,p-1) cs[j+c]=cs0[j];
            rep(j,c) cs[j]=cs0[j+p-1];
        }
        cout << cs[0] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main()
{
	int n, m;
	cin >> n >> m;
	if (n == 0 && m == 0) {
		return 0;
	} else {
		string in;
		REP(i, n) in = (char)(i)+in;
		REP(i, m)
		{
			int a, b;
			cin >> a >> b;
			in = in.substr(a - 1, b) + in.substr(0, a - 1) + in.substr(a + b - 1);
		}
		cout << int(in[0] + 1) << endl;
	}
}

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

using namespace std;

int main() {
    while (true) {
        int n, r, a[50];

        cin >> n >> r;
        if ( n == 0 && r == 0) { break; }

        for (int i = 0; i < n; i++) {
            a[i] = n-i;
        }

        while (r--) {
            int p, c;
            cin >> p >> c;
            rotate(a, a+p-1, a+p+c-1);
        }

        cout << a[0] << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int N, R, p, c;
int main() {
    while (cin >> N >> R && N) {
        vector <int> A(N,0);
        for (int i = 0; i < N; ++i) A[i] = N - i;
        for (int i = 0; i < R; ++i) {
            cin >> p >> c;
            rotate(A.begin(), A.begin()+p-1,A.begin()+c+p-1);
        }
        cout << A[0] << endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int input() {
	int input[51][2];
	cin >> input[0][0] >> input[0][1];								
	if (input[0][0] == 0 && input[0][1] == 0) {
		return 0;
	}
	for (char pos = 1; pos <= input[0][1]; pos++) {
		cin >> input[pos][0] >> input[pos][1];
	}																

	int whtop = 1;													
	whtop = input[input[0][1]][0];
	input[0][1]--;
	while (input[0][1] != 0) {

		if (input[input[0][1]][1] >= whtop) {
			whtop = input[input[0][1]][0] + whtop - 1;
		}
		else {
			whtop = whtop - input[input[0][1]][1];
		}
		input[0][1]--;
	}
	return input[0][0]-whtop+1;
}




int main()
{
	int output[1000];
	char topos = 0;
	while (1) {
		int check;
		check=input();
		if (check == 0)break;
		else {
			output[topos] = check;
			topos++;
		}
	}

	char sendpos = 0;
	while (sendpos < topos) {
		cout << output[sendpos] << endl;
		sendpos++;
	}


}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int d[51];

void init(int n){
  for(int i=0;i<51;i++){
    d[i]=n-i;
  }
}

int main(){
  int n,r;

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

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;
    for(int i = n;i > 0;i--)v.push_back(i);
    for(int i = 0;i < r;i++){
      vector<int> q(0);
      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() - 1;i++)cout << ans[i] << endl;
  cout << ans[ans.size() - 1];
}

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

using namespace std;

int main()
{
  int n, r;
  while(cin >> n >> r, n || r){
    int deck[50];
    for(int i = 0; i < n; i++) deck[i] = n - i;
    while(r--){
      int p, c;
      cin >> p >> c;
      --p;
      int tmp[50];
      for(int i = 0; i < c; i++) tmp[i] = deck[p + i];
      for(int i = p + c - 1; i >= c; i--) deck[i] = deck[i - c];
      for(int i = 0; i < c; i++) deck[i] = tmp[i];
    }
    cout << deck[0] << endl;
  }
  return 0;
}

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

int main(void){
  while(1){
    vector<int> f;
    int n, r, p, c;
    cin >> n >> r;
    if(n == 0 && r == 0) return 0;
    for(int i=n; i >= 0; i--){
      f.push_back(i);
    }


    for(int i=0; i < r; i++){
      cin >> p >> c;
      vector<int> t;
      for(int j=p-1; j < p+c; j++){
        t.push_back(f.at(j));
      }
      for(int j=p-1; j > 0; j--){
        f.at(j+c) = f.at(j);
      }
      for(int j=0; j < c; j++){
        f.at(j) = t.at(j);
      }


    }
    cout << f.front() << endl;
  }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int x[1000],y[1000];
int main(){
	int n,r,a,b;
	while(true){
		cin>>n>>r;
		if(n==0 && r==0){break;}
		for(int i=1;i<=n;i++){
			x[i]=n+1-i;
		}
		for(int i=0;i<r;i++){
			cin>>b>>a;
			for(int i=b;i<a+b;i++){
				y[i-b+1]=x[i];
			}
			for(int i=1;i<b;i++){
				y[i+a]=x[i];
			}
			for(int i=a+b;i<=n;i++){
				y[i]=x[i];
			}
			for(int i=1;i<=n;i++){
				x[i]=y[i];
			}
		}
		cout<<x[1]<<endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;

int main()
{
	int n, r;
	while (cin >> n >> r, n || r) {
		vector<PII> shuffles;
		for (int i = 0; i < r; ++i) {
			int p, c;
			cin >> p >> c;
			shuffles.push_back(make_pair(p, c));
		}
		reverse(shuffles.begin(), shuffles.end());
		int index = 0;
		for (int i = 0; i < shuffles.size(); ++i) {
			int p = shuffles[i].first, c = shuffles[i].second;
			if (index < c) {
				index += p - 1;
			} else if (index < c + p - 1) {
				index -= c;
			}
		}
		cout << n - index << endl;
	}
}