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>
using namespace std;

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

	while(true){
		vector<int> cards;
		int check[50]={0};
		cin >> n >> r;
		if(n == 0 && r == 0){
			break;
		}

		
		for(int i=n;i!=0;i--){
			cards.push_back(i);
		}
		vector<int> buf;
		for(int i=0;i<r;i++){
			cin >> p >> c;
			for(int j=0;j<c;j++){
				buf.push_back(cards[p+j-1]);
				check[p+j-1] = 1;
			}
			for(int j=0;j<n;j++){
				if(check[j] == 0){
					buf.push_back(cards[j]);
				}else{
					check[j] = 0;
				}
			}
			cards.clear();
			for(int j=0;j<n;j++){
				cards.push_back(buf[j]);
			}
			buf.clear();
		}

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

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;
			}
		}
	cout << card[0]  << "\n";
	}
	return 0;
}

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

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

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

#define itn long long
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)(n);i>=0;--i)
#define debug(x) cout << #x << "=" << (x) << endl;
const ll MOD=1e9+7;

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;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end

void solve(){
  while(1){
    int n,r;
    cin>>n>>r;
    if(!(n|r))return;
    vector<int> A(n);
    rep(i,n)
      A[n-1-i]=i+1;
    rep(i,r){
      int p,c;
      cin>>p>>c;--p;
      vector<int> newA(n,0);
      for(int j=p;j<p+c;j++)
        newA[j-p]=A[j];
      for(int j=0;j<p;j++)
        newA[j+c]=A[j];
      rep(j,n)
        if(!newA[j])
          newA[j]=A[j];
      A=newA;
    }
    cout<<A[0]<<endl;
  }
}
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  solve();
  return 0;
}