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(){
  int n,r;
  while(cin>>n>>r,n+r!=0){
    queue<int> yama;
    queue<int> x;
    queue<int> y;
    for(int i=n;i>=1;i--)
      yama.push(i);
    for(int i=0;i<r;i++){
      int p,c;
      cin>>p>>c;
      for(int i=0;i<p-1;i++){
	x.push(yama.front());
	yama.pop();
      }
      for(int i=0;i<c;i++){
	y.push(yama.front());
	yama.pop();
      }
      while(!x.empty()){
	yama.push(x.front());
	x.pop();
      }
      while(!y.empty()){
	yama.push(y.front());
	y.pop();
      }
    }
    cout<<yama.front()<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <map>
#include <deque>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n,r;
	
	while(cin >> n >> r , n){
		deque<int> card(n);
		rep(i,n)card[n-i-1]=i+1;

		rep(i,r){
			int p,c;
			cin >> p >> c;
			deque<int> t(c);
			rep(j,c)t[j] = card[p-1+j];
			rep(j,c)card.erase( remove(card.begin(),card.end(),t[c-1-j]),card.end() );
			rep(j,c)card.push_front(t[c-1-j]);
		}
		cout << card[0] << endl;
	}
}

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

using namespace std;

int main()
{
	int n, m, s, t;
	
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0){
			break;
		}
		queue<int> que, qu1, qu2, qu3;
		
		for(int i = n; i >= 1; i--){
			que.push(i);
		}
		while(m--){
			cin >> s >> t;
			for(int i = 0; i < s-1; i++){
				qu1.push(que.front());
				que.pop();
			}
			for(int i = 0; i < t; i++){
				qu2.push(que.front());
				que.pop();
			}
			while(!que.empty()){
				qu3.push(que.front());
				que.pop();
			}
			while(!qu2.empty()){
				que.push(qu2.front());
				qu2.pop();
			}
			while(!qu1.empty()){
				que.push(qu1.front());
				qu1.pop();
			}
			while(!qu3.empty()){
				que.push(qu3.front());
				qu3.pop();
			}
		}
		cout << que.front() << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<string>
#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;
	while(1){
		cin>>n>>r;
		if(n==0 && r==0)break;
		string s="";
		for(int i=n;i>=1;i--){
			s+=(char)(i+'0');
		}
		cout<<s<<endl;
		rep(i,r){
			int p,c;
			cin>>p>>c;
			string sub=s.substr(0,p-1);
			s.insert(p,sub);
			s.erase(0,p-1);
		}
		cout<<s[0]<<endl;
	}
	return 0;
}

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

using namespace std;

vector<int>card;

void cut(int p,int c){
  vector<int>res;
  for(int i=p;i<p+c;i++)res.push_back(card[i]);
  for(int i=0;i<p;i++)res.push_back(card[i]);
  for(int i=p+c;i<card.size();i++)res.push_back(card[i]);
  card=res;
}

int main(void){
  int n,r;

  while(cin >> n >> r, n|r){
    card.resize(n);
    for(int i=0;i<n;i++)card[i]=n-i;
    
    int p,c;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      cut(p-1,c);
    }
    cout << card[0] << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
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;
		}

		for (int i = 0; i < r; i++){
			int p, c, b[50];
			cin >> p >> c;
			for (int j = 0; j < p-1; j++){
				b[j] = a[j];
			}
			for (int j = 0; j < c; j++){
				a[j] = a[p + j-1];
			}
			for (int j = 0; j < p-1; j++){
				a[c + j] = b[j];
			}
		}

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

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = 998244353LL;
const double pi = acos(-1.0);

void re(VI & v, int p, int c) {
	VI P, C;
	rep(i, p - 1)P.pb(v[i]);
	FOR(i, p - 1, p + c - 1)C.pb(v[i]);
	rep(i, sz(C))v[i] = C[i];
	FOR(i, c, p + c - 1)v[i] = P[i - c];
}

int main() {
	int n, r;
	while (cin >> n >> r && (n || r)) {
		VI a(n); rep(i, n)a[i] = n - i;
		rep(i, r) {
			int p, c; cin >> p >> c;
			re(a, p, c);
		}
		Cout(a[0]);
	}
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int input(char s[]);

int main() {
	int cnt,ans[10000],n, r,brk=0,p,c,x[50],xs[50];
	for (int i = 0; i < 50; i++)
		x[i] = xs[i] = i;

	//while (1) {
	for (cnt=0; cnt<10000; cnt++) {
		scanf("%d %d", &n, &r);
		if (n == 0 && r == 0)
			brk = 1;
		if (brk == 1)
			break;
		for (int i = 0; i < r&&brk == 0; i++) {
			scanf("%d %d", &p, &c);
			for (int j = 0; j < c; j++)
				x[j] = xs[j + p - 1];
			for (int j = c; j < c + p - 1; j++)
				x[j] = xs[j - c];
			for (int j = 0; j < n; j++)
				xs[j] = x[j];}
			ans[cnt] = n - x[0];
	}
	for (int i = 0; i < cnt; i++)
		printf("%d\n", ans[i]);
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#ifndef repeat
#define repeat(i,n) for (int i = 0; i < (n); ++i)
#endif
#ifndef repeat_from
#define repeat_from(i,m,n) for (int i = (m); i < (n); ++i)
#endif
#ifndef repeat_one
#define repeat_one(i,n) for (int i = 1; i <= (n); ++i)
#endif
#ifndef repeat_rev
#define repeat_rev(i,n) for (int i = (n)-1; 0 <= i; --i)
#endif
#ifndef foreach
#define foreach(it, cont) for (typeof(cont.begin()) it = cont.begin(); it != cont.end(); ++it)
#endif
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    while (true) {
        int n, r; cin >> n >> r;
        if (n == 0 and r == 0) break;
        vector<int> v(n); repeat (i,n) v[i] = n-i;
        repeat (i,r) {
            int p, c; cin >> p >> c;
            vector<int> vp(v.begin(),   v.begin()+p-1);
            vector<int> vc(v.begin()+p-1, v.begin()+p-1+c);
            copy(vp.begin(), vp.end(), v.begin()+c);
            copy(vc.begin(), vc.end(), v.begin());
        }
        cout << v.front() << endl;
    }
    return 0;
}