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

int n, r, p, c;
vector<int> cards(50);

void shuffle(int p, int c) {
	reverse(cards.begin(), cards.begin() + p);
	reverse(cards.begin() + p, cards.begin() + p + c);
	reverse(cards.begin(), cards.begin() + p + c);
}

int main() {
	while (1) {
		cin >> n >> r;
		if ( ! n && ! r) break;

		iota(cards.rend() - n, cards.rend(), 1);
		for (int i=0; i<r; ++i) {
			cin >> p >> c;
			shuffle(p - 1, c);
		}
		cout << cards[0] << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int card[51],s[51];
int n,r;
void shuffle(int p,int c){
	for(int i=1;i<p;i++){
		s[i]=card[i];
	}
	for(int i=1;i<=c;i++){
		card[i]=card[p-1+i];
	}
	for(int i=1;i<p;i++){
		card[i+c]=s[i];
	}
}


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

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

using namespace std;

vector<int> Deck;

void shuffle(int p, int c) {
  vector<int> tmp = Deck;
  for(int i=0; i<Deck.size(); i++) {
    if(i<c) {
      Deck[i] = tmp[p+i-1]; // -1不要?
    }
    else if(i) {
      Deck[i] = tmp[i-c];
    }
  }
}

int main() {
  int n, r;

  while(cin>>n>>r && n>0) {
    Deck.clear();
    for(int i=0; i<n; i++) {
      Deck.push_back(n-i);
    }
    for(int i=0; i<r; i++) {
      int p, c;
      cin>>p>>c;
      shuffle(p, c);
    }
    cout<<Deck[0]<<endl;
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=true;

int d[55];

void init(int n){
  for(int i=0;i<51;i++){
    d[i]=n-i;
  }
}

int main(){
  int n,r;

  while(true){
    cin>>n>>r;
    if(n==0&&r==0)break;
    init(n);
    for(int i=0;i<r;i++){    
      int p,c;
      cin>>p>>c;

      //????????????p~p+c?????£??\
      int cnt=0;
      int tmp[55];
      for(int j=p-1;j<p-1+c;j++){
	tmp[cnt]=d[j];
	cnt++;
      }

      //1~p-1?????§???c?????????????????¨???
      for(int j=p-1;j>=0;j--){
	d[j+c]=d[j];
      }
      
      //p~p+c?????§??????????????£?????????
      for(int j=0;j<c;j++){
	d[j]=tmp[j];
      }
      if(debug)for(int j=0;j<n;j++)cout<<d[j]<<" ";
      if(debug)cout<<endl;
    }
    cout<<d[0]<<endl;
  }
  return 0;
}

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

using namespace std;

int main(){
  int n,r,i,j,p,c;
  cin >> n >> r;
  while(n!=0&&r!=0){
    vector <int> cards;
    for(i=0;i<n;i++){
      cards.push_back(i+1);
    }
    for(i=0;i<r;i++){
      cin >> p >> c;
      for(j=0;j<c;j++){
	cards.push_back(cards[n-p-c+1]);
	cards.erase(cards.begin()+n-p-c+1);
      }
      //for(j=0;j<n;j++) cout << j+1 << ":" << cards[j] << endl; 
    }
    
    cout << cards[n-1] << endl;
    
    cin >> n >> r;
  }
  
  return 0;
}

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

using namespace std;

int main(){
	vector<int> cards;
	vector<int> shuffuleCards;
	vector<int> ::iterator cardsIterator;
	vector<int> ::iterator shuffuleIterator;
	int n,r,p,c;

	while(cin >> n >> r, n && r){
		cards.clear(); //?????????
		// ?????????????±±??????
		for (int i = 0; i < n; ++i){
			cards.push_back(i+1);
		}
		// ?????£?????????
		while(cin >> p >> c, r--){
			cardsIterator = cards.end();
			cardsIterator -= p + (c - 1);
			while(c--){
				cards.push_back(*cardsIterator);
				cards.erase(cardsIterator);
			}
			if (r == 0){
				break;
			}
		}
		// ???????????????????????¨???
		cout << cards.back() << endl;
	}
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int n, r;
  while (cin >> n >> r, n|r) {
    vector<int> deck(n);
    REP(i, n) { deck[i] = n - i; }
    REP(i, r) {
      int p, c; cin >> p >> c;
      reverse(deck.begin(), deck.begin() + p + c - 1);
      reverse(deck.begin(), deck.begin() + c);
      reverse(deck.begin() + c, deck.begin() + p + c - 1);
    }
    cout << deck.front() << endl;
  }
}

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

int main() {
	int n,r,p,c,tmp;
	while(cin >> n >> r){
	if(n==0)
		break;
	deque<int> library;
	vector<int> stack;
	for(int i=1;i<=n;i++)
	library.push_back(n-i+1);
	for(int i=0;i<r;i++){
		cin >> p >> c;
		for(int j=p+c-1;j<library.size();){
			stack.push_back(library.back());
			library.pop_back();
		}
		for(int j=0;j<c;j++){
			tmp=library.back();
			library.pop_back();
			library.push_front(tmp);
		}
		while(!stack.empty()){
			library.push_back(stack.back());
			stack.pop_back();
		}
	}
	cout << library.front() << endl;
	library.clear();
	stack.clear();
	}
	// your code goes here
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

void solve(int n,int m){
    vector<int> a(n);
    iota(a.begin(),a.end(),1);
    reverse(a.begin(),a.end());
    rep(i,m){
        vector<int> na(n);
        int p,c;
        cin>>p>>c;
        rep(i,p-1){
            na[i+c]=a[i];
        }
        REP(i,p-1,p+c-1){
            na[i-p+1]=a[i];
        }
        REP(i,p+c-1,n)na[i]=a[i];
        swap(na,a);
    }
    cout<<a[0]<<endl;
}

int main(){
    int n,m;
    while(cin>>n>>m,n!=0){
        solve(n,m);
    }
    return 0;
}

C++: #include <cstdio>
#include <stack>
#include <queue>
using namespace std;
int main() {
    int n, r;
    while (scanf("%d%d",&n,&r)) {
        if (!n&&!r) break;
        deque<int> deq;
        for (int i=n; i>=1; i--) deq.push_back(i);
        for (int i=0; i<r; i++) {
            int p, c; scanf("%d%d",&p,&c);
            stack<int> ue, shita;
            for (int j=0; j<p-1; j++) {
                ue.push(deq[0]);
                deq.pop_front();
            }
            for (int j=0; j<c; j++) {
                shita.push(deq[0]);
                deq.pop_front();
            }
            while (!ue.empty()) {
                deq.push_front(ue.top());
                ue.pop();
            }
            while (!shita.empty()) {
                deq.push_front(shita.top());
                shita.pop();
            }
//            for (int i=0; i<n; i++) printf("%d%c",deq[i],i==n-1?'\n':' ');
//            puts("");
        }
        printf("%d\n",deq[0]);
    }
}