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 <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;



int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	while (1) {
		ll n, r; scanf("%lld %lld", &n, &r);
		if (n == 0 && r == 0) break;
		deque<ll> q;
		stack<ll> s1,s2;
		for (ll i = n; i >= 1; i--) q.push_back(i);
		for (ll i = 0; i < r; i++) {
			ll p, c; scanf("%lld %lld", &p, &c);
			p--;
			for (ll j = 0; j < p; j++) {
				s1.push(q.front());
				q.pop_front();
			}
			for (ll j = 0; j < c; j++) {
				s2.push(q.front());
				q.pop_front();
			}
			while (!s1.empty()) {
				q.push_front(s1.top());
				s1.pop();
			}
			while (!s2.empty()) {
				q.push_front(s2.top());
				s2.pop();
			}
		}
		printf("%lld\n", q.front());
	}
	return 0;
}

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

int main(){
  int n,r;
  cin >> n >> r;
  vector<int> ans;
  while(n||r){
    vector<int> card(n);
    for(int i = 0; i < r; i++){
      card[i] = n - i;
    }
    for(int i = 0; i < r; i++){
      int p,c;
      cin >> p >> c;
      int start = p - 1;
      int end = p + c -2;
      vector<int> sub(c);
      for(int j = 0; j < c;j++){
        sub[i] = card[start+i];
      }
      for(int j = 0; j < c; j++){
        card[end-j] = card[start-j];
      }
      for(int j = start - 1; j > c - 1;j++){
        card[j] = card[j-c];//
      }
      for(int j = 0; j < c; j++){
        card[j] = sub[j];
      }
    }
    ans.push_back(card[0]);
    cin >> n >> r;
  }
  for(int i = 0; i < ans.size(); i++){
    cout << ans[i] << endl;
  }
}

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

using namespace std;

int main(){
  int n,r;

  while(cin>>n>>r,n){
    int p,c;
    vector<int> cards;
    
    for(int i=n;i>0;--i){
      cards.push_back(i);
    }
    
    for(int i=0;i<r;++i){
      cin>>p>>c;
      vector<int> temp;
      for(int j=0;j<c;++j){
	temp.push_back(cards[p-1]);
	cards.erase(cards.begin()+p-1);
      }
      
      int j=0;
      for(auto i:temp){
	cards.insert(cards.begin()+j,i);
	j++;
      }
    }
    cout<<cards[0]<<endl;
  }
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,R;
    cin >> N >> R;
    while(N){
        vector<int> V(N);
        iota(V.rbegin(), V.rend(), 1);
        for(auto i:V)cout << i << endl;
        rep(i,0,R){
            int p,c;
            cin >> p >> c;
            vector<int> tmp(p + c - 1);
            rep(j,0,c){
                tmp[j] = V[j + p - 1];
            }
            rep(j,c,p+c-1){
                tmp[j] = V[j-c];
            }
            rep(j,0,p+c-1){
                V[j] = tmp[j];
            }
        }
        cout << V[0] << endl;
        cin >> N >> R;
    }
}

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


using namespace std;
int main()
{
    int n,r;
    while(cin>>n>>r){
        
        if(n==0&&r==0)break;
        stack<int> st1;
        for(int i=0; i<n; i++){
            st1.push(i+1);
        }
        
        for(int rop=0; rop<r; rop++){
            int p,c;
            cin>>p>>c;
            stack<int> st2,st3;
            for(int i=0; i<p-1; i++){
                st2.push(st1.top());
                st1.pop();
            }
            
            for(int i=0; i<c; i++){
                st3.push(st1.top());
                st1.pop();
            }
            
            while (!st2.empty()) {
                st1.push(st2.top());
                st2.pop();
            }
            
            while (!st3.empty()) {
                st1.push(st3.top());
                st3.pop();
            }
        }
        
        cout<<st1.top()<<endl;
    }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int C[51];
    int n, r; //カードの枚数、シャッフル回数
    int p, c; //山の一番上からp枚目の札から連続したc枚の札を抜き山の上にそのまま置く
    while(true){
        cin >> n >> r;
        if(n + r == 0) break;

        //山全体の構成
        for(int i = 0; i < n; i++){
            C[i] = n - i;
        }
        // for(int i = 0 ; i < n; i++){
        //     cout << C[i] << endl;
        // }


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

            //シャッフルする
            rotate(C, C + p - 1, C + p - 1 + c);
            // for(int i = 0; i < n; i++){
            //     cout << C[i] << endl;
            // }  
        }
        cout << C[0] << endl;
    }
}

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

using namespace std;

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

    while(true){
        stack<int> x;
        cin >> n >> r;
        if(n == 0 && r == 0) break;

        for(int i=1; i<=n; i++){
            x.push(i);
        }

        for(int i=0; i<r; i++){
            stack<int> pp, cc;
            cin >> p >> c;
            for(int i=0; i<p-1; i++){
                pp.push(x.top());
                x.pop();
            }
            
            for(int i=0; i<c; i++){
                cc.push(x.top());
                x.pop();
            }

            for(int i=0; i<p-1; i++){
                x.push(pp.top());
                pp.pop();
            }
            for(int i=0; i<c; i++){
                x.push(cc.top());
                cc.pop();
            }
        }

        cout << x.top() << endl;
    }

    return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <iterator>
#include <iostream>
#define MAX_CARD 51
using namespace std;

int main(void) {
	int n, r;
	for (;;) {
		cin >> n >> r;
		if (n == 0 && r == 0) {
			break;
		}
		vector<int> card;
		for (int i = n; i > 0; i--) {
			card.push_back(i);
		}

		for (int i = 0; i < r; i++) {
			int p, c;
			cin >> p >> c;
			vector<int> buf;
			for (int i = p - 1; i < p + c - 1; i++) {
				buf.push_back(card[i]);
				// printf("%d\n", card[i]);
			}

			for (int i = 0, j = buf.size(); i < p - 1; i++, j++) {
				buf.push_back(card[i]);
				// printf("%d\n", card[i]);
			}

			for (int i = p + c - 1, j = buf.size(); i < card.size(); i++, j++) {
				buf.push_back(card[i]);
				// printf("%d\n", card[i]);
			}

			for (int i = 0; i < card.size(); i++) {
				card[i] = buf[i];
				//printf("%d\n", card[i]);
			}
			//printf("\n");

			// shuffle(card, p, c);
		}
		printf("%d\n", card[0]);
	}
	return 0;
}