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>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)

int main() {
    int n, r;
    while (cin >> n >> r && n) {
        int p, c;
        int a[n];
        rep(i, n) {
            a[i] = n - i;
            //cout << a[i] << " ";
        }
        //cout << endl;
        rep(i, r) {
            cin >> p >> c;
            rotate(a, a + p - 1, a + p + c - 1);
            /*
            rep(i, n) {
                cout << a[i] << " ";
            }
            cout << endl;*/
        }
        cout << a[0] << endl;
    }
}

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

#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define ALL( a )        (a).begin(), (a).end()             

int main() {
	int n, r, p, c;

	while( 1 ) {
		cin >> n >> r; if( n == 0 && r == 0 ) break;
		vector<int> card( n );
		vector<int> tmp( n );
		// if n == 3 -> 3 2 1
		REP( i, n ) card[i] = n - i;

		REP( i, r ) {
			cin >> p >> c;
			tmp = card;
			REP( j, p + c - 1 ) {
				if( j < c ) card[j] = tmp[j + p - 1];
				else		card[j] = tmp[j - c];
			}
		}
		cout << card[0] << endl;
	}

}

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

using namespace std;

void solve()
{
	int n, r;
	while(cin >> n >> r, n || r)
	{
		vector<int> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			Vec[i] = n - i;
		}
		while(r--)
		{
			int p, c;
			cin >> p >> c;
			vector<int> VecBuf = Vec;
			int pos = 0;
			for(int i = p - 1; i < p + c - 1; ++i)
			{
				Vec[pos] = VecBuf[i];
				++pos;
			}
			for(int i = 0; i < p - 1; ++i)
			{
				Vec[pos] = VecBuf[i];
				++pos;
			}
			for(int i = p + c - 1; i < n; ++i)
			{
				Vec[pos] = VecBuf[i];
				++pos;
			}
		}
		cout << Vec[0] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

int main(){
	int n,r;
	int c= 0;
	while((cin >> n)&&(cin >> r)&&(n!=0)&&(r!=0)){
		int a[n];
		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[p+c];
			//cout << p << endl;
			//cout << c << endl;
			//cout << endl;
			if(n!=c){
				for(int j=0;j<p;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;j++){
					a[j] = b[j];	
					//cout << "a[" << j << "]" << a[j] << endl;
				//	cout << "b[" << j << "]" << b[j] << endl;
				}
			}
		}
		cout << a[0] << endl;
	}
}

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

int main() {
	int N, R;
	vector<int> V, W;
	while (cin >> N >> R) {
		if (N == 0 && R == 0) break;
		V.clear();
		for (int i = 0; i < N; i++) {
			V.push_back(N - i);
		}
		for (int i = 0; i < R; i++) {
			int P, C;
			W.clear();
			cin >> P >> C;
			for (int j = P - 1; j < P + C - 1; j++) {
				W.push_back(V[j]);
			}
			for (int j = 0; j < P - 1; j++) {
				W.push_back(V[j]);
			}
			for (int j = P + C - 1; j < N; j++) {
				W.push_back(V[j]);
			}
			V = W;
		}
		cout << V[0] << endl;
	}
}

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

using namespace std;

int top_search(int,int,int,int *);
int main(){
	int n,r,c,p;
	int cnt=0;
	int top[50];
	while(1){
		cin>>n>>r;
		if(n==0&&r==0)
			break;
		int *hanahuda=new int[n];

		for (int i = n-1; i>=0 ; i--)
			hanahuda[i]=n-i;

		for(int i=0;i<r;i++){
			cin>>p>>c;
			top[cnt]=top_search(n,p,c,hanahuda);
		}
		delete[] hanahuda;
		cnt++;
	}
	for(int m=0;m<cnt;m++)
		cout<<top[m]<<endl;
	return 0;
}
int top_search(int n,int p,int c,int *hanahuda){
	int cnt=0;
	for(int k=p-1;k<p+c-1;k++){

		int nokori=hanahuda[k];

		for(int l=p-2;l>=0;l--)
			hanahuda[l+1]=hanahuda[l];


		hanahuda[cnt]=nokori;
		cnt++;
	}

	return *hanahuda;
}

C++: //
//  main.cpp
//  AOJ1129
//
//  Created by aki33524 on 2014/07/15.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[])
{
    int n, r;
    while(cin>>n>>r, n|r){
        vector<int> deck(n);
        for(int i=0; i<n; i++)
            deck[n-i-1] = i+1;
        
        int p, c;
        for(int i=0; i<r; i++){
            cin >> p >> c;
            vector<int> tmp = deck;
            for(int j=0; j<c; j++){
                deck[j] = tmp[j+p-1];
            }
            for(int j=0; j<p-1; j++){
                deck[j+c] = tmp[j];
            }
        }
        cout << deck[0] << endl;
    }
    
    return 0;
}

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

using namespace std;

int main(){

	int n,r;
	int p,c;
	vector<int> dek;
	vector<int>::iterator ite;
	queue<int> tmp;

	while(1){

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

		if(!dek.empty()) dek.clear();
		for(int i=1;i<=n;i++) dek.push_back(i);

		for(int i=0;i<r;i++){
			cin>>p>>c;
			ite=dek.begin();
			advance(ite,n-p-c+1);
			for(int i=0;i<c;i++){
				tmp.push(*ite);
				ite=dek.erase(ite);
			}
			while(!tmp.empty()){
				dek.push_back(tmp.front());
				tmp.pop();
			}
		}
		cout<<dek[n-1]<<endl;
	}

}

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

int main() {
  int n, r;
  while (cin >> n >> r, n || r) {
    vector<int> a;
    a.reserve(n);
    for (int i = 0; i < n; ++i) {
      a.emplace_back(n - i);
    }
    for (int i = 0; i < r; ++i) {
      int p, c;
      cin >> p >> c;
      vector<int> b;
      b.reserve(n);
      for (int j = p - 1; j < p - 1 + c; ++j) {
        b.emplace_back(a[j]);
      }
      for (int j = 0; j < n; ++j) {
        if (p - 1 <= j && j < p - 1 + c) continue;
        b.emplace_back(a[j]);
      }
      a = b;
    }
    cout << a[0] << endl;
  }
}

C++: 
#include<bits/stdc++.h>
using namespace std;
int x[100];
int y[100];
int card [100];
int n,r;
int ans[1000];
int counter;
bool input(){
    for(int i=0;i<100;i++){
    x[i]=0;
    y[i]=0;
    }
    cin >>n>>r;
    for(int i=0;i<r;i++){
    cin>>x[i]>>y[i];
    }
    if(n==0){
    return false;
    }
    else{
     return true;
    }
}
void solve(){
    for(int i=0;i<100;i++){
        card[i]=i+1;
    }
    for(int i=0;i<r;i++){
        for(int k=0;k<y[i];k++){
            int a=card[x[i]+y[i]-2];
            for(int j=x[i]+y[i]-1;j>0;j--){
                card[j]=card[j-1];
            }
            card[0]=a;
            
        }
    for(int j=1;j<=y[i]/2;j++){
int remainder=card[j];
card[j]=card[y[i]-j];
card[y[i]-j]=remainder;
}
    }
 
    ans[counter]=card[0];
 counter+=1;
}
  
  
  
int main (){
counter=0
    while(input()){
    solve();
    }
for(int j=0;j<=counter;j++){
cout<<ans[counter]<<endl;
}
return 0;
}