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 <algorithm>
#include <vector>
using namespace std;

int main(){
	int hanafuda[51]{0};
	int tmpp[51]{0};
	vector<int> ansvec;

	for (;;){
		int n, r;
		cin >> n >> r;
		if (n == 0) break;

		for (int i = n; i >= 1; i--){
			hanafuda[i] = i;
		}

		for (int i = 0; i < r; i++){
			int p, c;
			cin >> p >> c;
			for (int j = 0; j < p - 1; j++){
				tmpp[p - 1 - j] = hanafuda[n - j];
			}
			for (int j = 0; j < c ; j++){
				hanafuda[n - j] = hanafuda[n - (p - 1) - j];
			}
			for (int j = 0; j < p - 1; j++){
				hanafuda[n - c - j] = tmpp[p - 1 - j];
			}
		}
		ansvec.push_back(hanafuda[n]);
	}

	for (int ans : ansvec){
		cout << ans << endl;
	}

	return 0;
}

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

using namespace std;

int main(void)
{
	int n, r;
	while(cin >> n >> r && n > 0){
		vector<int> card(n);
		//cardを初期化
		for(int i=0;i<n;i++){
			card[i] = n-i;
		}
		for(int i=0;i<r;i++){
			int p, c;
			cin >> p >> c;
			rotate(card.begin(), card.begin()+p-1, card.begin()+p+c-1);
		}
		cout << card[0] << 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++)
		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();
	cout<<solve()<<endl;
  }
  return 0;
}

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;
	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=top_search(n,p,c,hanahuda);
			cout<<top<<endl;
		}
		delete[] hanahuda;
		cnt++;
	}
	for(int m=0;m<cnt;m++)
		
	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++: #include<iostream>
using namespace std;

int main(){
	int n, r, p, c;
	int card[50], tmp;

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

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

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

			for(int j=0; j<c; j++){
				tmp = card[p-1+j];
				for(int k=p-2+j; k>=j; k--){
					card[k+1] = card[k];
				}
				card[j] = tmp;
			}
			for(int k=0;k<n;k++)
				cout << card[k] << "\n";
			cout << "\n";

		}
	
	}
	return 0;
}

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

using namespace std;

int solve(int n,int r){
    vector<pair<int,int> >p;
    for(int i=0;i<r;i++){
        int a,b;
        cin >> a >> b;
        p.push_back(make_pair(a,b));
    }

    int x = 1;
    for(vector<pair<int,int> >::iterator it=p.end();
        it != p.begin();
        --it){
        int a = (*it).first;
        int b = (*it).second;
        if(x<=b){
            x = x + a - 1;
        }else if(x<=a+b){
            x = x - b;
        }
    }
    cout << n-x+1 << endl;
}

int main(){
    int n,r;
    while(cin >> n >> r){
        if(n==0 && r==0){
            break;
        }
        solve(n,r);
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;

int main(){
  int n,r;
  int p,c;
  int a[100],b[100];

  while(1){
    scanf("%d %d",&n,&r);
    if(n==0 && r==0) break;
    rep(i,n) a[i]=n-i;
    rep(i,r){
      scanf("%d %d",&p,&c);
      rep(j,p+c-1){
        b[j]=a[j];
      }
      rep(j,p-1){
        a[j+c]=b[j];
      }
      rep(j,c) a[j]=b[j+p-1];
    }
    printf("%d\n",a[0]);
  }

  return 0;

}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;

int main(){
	int N,R;
	while(cin>>N>>R,N||R){
		int P,C;
		vector<int> card;
		for(int i=1;i<=N;i++){
			card.push_back(i);
		}
		for(int i=0;i<R;i++){
			cin>>P>>C;
			vector<int>::iterator a,b;
			card.resize(card.size()+C);
			a = card.end()-C-P-C+1; b = card.end()-C-P+1;
			for(int j=0;j<C;j++){
				card[card.size()-(C-j)] = *(a+j);
			}
			card.erase(a,b);
		}
		printf("\t%d\n",card.back());
	}
	return 0;
}

C++: //============================================================================
// Name        : aoj1129.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int n, r, card[50], p, c;
	while(1){
		cin >> n >> r;
		if(n == 0 && r == 0){
			break;
		}
		for(int i = 0;i < n;i++){
			card[i] = i + 1;
		}
		for(int i = 0;i < r;i++){
			cin >> p >> c;
			int tmp[50];
			//cout << "c" << endl;
			for(int j = 0;j < c;j++){
				tmp[n - 1 - j] = card[n - p - j];
				//cout << n - 1 - j << " " << n - p - j << endl;
			}
			//cout << "p" << endl;
			for(int j = 0;j < p - 1;j++){
				tmp[n - c - 1 - j] = card[n - 1 - j];
				//cout << n - c - 1 - j << " " << n - 1 - j << endl;
			}
			for(int j = 0;j < p - 1 + c;j++){
				card[n - 1 - j] = tmp[n - 1 - j];
			}
		}
		cout << card[n - 1] << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
	int n, r;
	int card[50], shuf[50];
	while(cin >> n >> r){
		if(!n) break;
		for(int i=0;i<n;i++) card[i] = n-i;
		for(int i=0;i<r;i++){
			int p, c; cin >> p >> c;
			int j=0;
			for(j=0;j<c;j++) shuf[j] = card[p-1+j];
			for(j=c;j<c+p-1;j++) shuf[j] = card[j-c];
			for(j=c+p-1;j<n;j++) shuf[j] = card[j];
			memcpy(card,shuf,sizeof(card));
		}
		cout << shuf[0] << endl;
	}
}