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>
#define MAX 50

using namespace std;

void cut(int[],int,int);

int main(void){
	int p,c;

	for(int n,r;cin >> n >> r,n||r;){
		int card[MAX];
		for(int i=0;i<n;i++)
			card[i]=n-i;

		for(int i=0;i<r;i++){
			cin >> p >> c;
			cut(card,p,c);
		}

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

	return 0;
}

void cut(int card[],int p,int c){
	int tmp[c];

	for(int i=0;i<c;i++)
		tmp[i]=card[p+i];

	for(int i=1;i<=p;i++)
		card[p+c-i]=card[p-i];

	for(int i=0;i<c;i++)
		card[i]=tmp[i];
}

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

using namespace std;

int n[10000]={},r[10000]={};
int p[10000][50] = {};
int c[10000][50] = {};
int i=0;

int d[50]={};
int e[50] = {}; //今の状態
int e2[50] = {};

int main(){
    while(1){
        scanf("%d %d",&n[i],&r[i]);
        if(n[i]== 0 && r[i]== 0){
            break;
        }
        for(int j=0;j<r[i];j++){
            scanf("%d %d",&p[i][j],&c[i][j]);
        }
        i++;
    }
    int times = i;
    for(i=0;i<times;i++){
        //初期化
        int s=0;
        for(int k = n[i]; k>0;k--){
            e[s] = k;
            s++;
        }
        for(int j=0;j<r[i];j++){
            s=0;
            for(int t=p[i][j]-1;t<p[i][j]+c[i][j]-1;t++){
                d[s] = e[t];
                s++;
            }
            for(int t = 0;t < n[i];t++){
                e2[t] = e[t];
            }
            for(int t = 0;t<c[i][j];t++){
                e[t] = d[t];
            }
            s = 0;
            for(int t=c[i][j];t<p[i][j]+c[i][j]-1;t++){
                e[t] = e2[s];
                s++;
            }
            for(int t=0;t<n[i];t++){
                cout<<e[t]<<endl;
            }
            puts("");

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

    return 0;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    int n,r;
    while (cin >> n >> r , n||r) {
        vector<int> a(n);
        REP(i,n) a[i] = n-i;
        REP(i,r) {
            int p,c;
            cin >> p >> c;
            vector<int> temp;
            REP(i,p-1) temp.pb(a[i]);
            a.erase(a.begin(), a.begin()+p-1);
            a.insert(a.begin()+c, ALL(temp));
        }
        cout << a[0] << endl;
    }
    return 0;
}

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

int solve(int n,int r){
    vector<int> m;
    for(int i=0;i<n;i++){
        m.push_back(i);
    }
    for(int i=0;i<r;i++){
        int p,c;
        scanf("%d %d",&p,&c);
        rotate(m.begin(),m.begin()+p-1,m.begin()+p+c-1);
    }
    return n-m[0];
}

int main(){
    while(1){
        int n,r;
        scanf("%d %d",&n,&r);
        if(n==0&&r==0) return 0;
        printf("%d\n",solve(n,r));
    }
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
using namespace std;

int n,r,p,c;
int before[50],after[50],tmp[50];

void init(){
	for(int i=0;i<50;i++)
		after[i]=tmp[i]=0;
}

bool input(){	
	int i;
	cin>>n;
	cin>>r;
	for(i=0;i<n;i++)
		before[i]=n-i;	
	return 1;
}

void Shuffle(int b[], int a[], int t[]){
	int j;
	for(j=0;j<c;j++){
			a[j]=b[p-1+j];
			t[j]=b[p-1+j];
		}
		for(j=0;j<p;j++){
			a[c+j]=b[j];
			t[c+j]=b[j];
		}
		for(j=0;j<n;j++)
			b[j]=t[j];
}


int solve(){
	for(int i=0;i<r;i++){
		cin>>p>>c;
		Shuffle(before,after,tmp);
	}
	return after[0];
}


int main(){
	n=r=1;
  while((n!=0)&&(r!=0)){
	init(),input();
	if(after[0]!=0)
		cout<<solve()<<endl;
  }
  return 0;
}

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

using namespace std;
int n, r, p, c;

int main(){
	while (cin >> n >> r && n){
		int a[55];
		for (int i = 0; i < r; i++){
			a[i] = i + 1;
		}
		for (int j = 0; j < r; j++){
			cin >> p >> c;
			rotate(a + n - p - c + 1, a + n - p + 1, a + n + 1);
		}
		cout << a[n - 1] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
using namespace std;

int n,r,p,c;
int before[50],after[50],tmp[50];

void init(){
	for(int i=0;i<50;i++)
		before[i]=after[i]=tmp[i]=0;
}

bool input(){	
	int i;
	cin>>n;
	cin>>r;
	if((n==0) && (r==0))
		return false;
	for(i=0;i<n;i++)
		before[i]=n-i;	
	return true;
}

void Shuffle(int b[], int a[], int t[]){
	int j;
	for(j=0;j<c;j++){
		a[j]=b[p-1+j];
		t[j]=b[p-1+j];
	}
	for(j=0;j<p-1;j++){
		a[c+j]=b[j];
		t[c+j]=b[j];
	}
	for(j=0;j<n;j++)
		b[j]=t[j];
}


int solve(){
	for(int i=0;i<r;i++){
		cin>>p>>c;
		Shuffle(before,after,tmp);
	}
	return after[0];
}


int main(){
  while(init(),input()){
	cout<<solve()<<endl;
  }
  return 0;
}

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

int main() {
	// your code goes here
	long long n, r;
	std::vector<long long> arr1(60);
	std::vector<long long> arr2(60);
	while (1) {
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		for (auto i = 0; i < 60; i++) arr1[i]=i;
		for (auto i = 0; i < r; i++) {
			long long p, c;
			cin >> p >> c;
			// cout << "input " << p << " " << c << endl;
			
			for (auto j = 0; j < c; j++) {
				long long copy_idx = n-p-c+j+2;
				// cout << "copy " << arr1[copy_idx] << endl;
				arr2[n-c+j+1] = arr1[copy_idx];
			}
			for (auto j = 0; j < p-1; j++) {
				arr1[n-p-c+j+2] = arr1[n-p+j+2];
			}
			for (auto j = 0; j < c; j++) {
				arr1[n-c+j+1] = arr2[n-c+j+1];
			}
		}
		cout << arr1[n] << endl;
	}
	return 0;
}

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

int main() {
	int n, r;
	int p, c;
	int i, j, k;
	int t[100];
	int card[100];
	while(cin >> n >> r, n) {
		for(i=0;i<n;i++) {
			card[i] = n-i;
		}
		for(i=0;i<r;i++) {
			cin >> p >> c;
			for(j=0;j<p;j++) {
				t[j] = card[j];
			}
			for(j=0;j<c;j++) {
				card[j] = card[j+p-1];
			}
			for(j=0;j<p;j++) {
				card[j+c] = t[j];
			}
		}
		cout << card[0] << endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;

#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;

int main() {
  while (true) {
    int n, l;
    cin >> n >> l;
    if (n == 0) break;
    int cards[n], next[n];
    for (int i = n; i > 0; i--) {
      cards[n-i] = i;
    }

    for (int i = 0; i < l; i++) {
      int p, c;
      cin >> p >> c;
      for (int j = p-1; j < p+c-1; j++) {
	next[j-p+1] = cards[j];
      }
      for (int j = 0; j < p-1; j++) {
	next[c+j] = cards[j];
      }
      for (int j = p+c-1; j < n; j++) {
	next[j] = cards[j];
      }
      for (int j = 0; j < n; j++) {
	cards[j] = next[j];
      }
    }
    cout << cards[0] << endl;
  }
}