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;

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

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

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

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

using namespace std;

int main(){
  int maisu[50];
  int katto;
  int swap[50];
  int p,c;
  int i,j=0;

  for(i=0; i<50; i++){
    maisu[i] = i;
  }

  cout << maisu[0] << endl;

  cin >> katto;

  while(j <= katto){

    while(true){
      scanf("%d%d",&p,&c);
      if(p == 0 && c == 0){
	break;
      }
      for(i=0; i<c; i++){
	swap[i] = maisu[i + p-1];
      }
      for(i = 0; i<p-1; i++){
	swap[i+c] = maisu[i];
      }
      for(i=0;i<p+c-1; i++){
	maisu[i] = swap[i];
      }
    }
    if(p == 0 && c == 0){
	break;
    }
  }
    cout << maisu[0] << endl;

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
//#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n, r;
    deque<int> d(50);
    stack<int> s, t;
    while (cin >> n >> r && n) {
        FOR(i, 0, n)d[i] = n - i;
        while (r--) {
            int p, c; cin >> p >> c;
            FOR(i, 0, p - 1) {
                s.push(d.front());
                d.pop_front();
            }
            FOR(i, 0, c) {
                t.push(d.front());
                d.pop_front();
            }
            while (!s.empty()) {
                d.push_front(s.top());
                s.pop();
            }
            while (!t.empty()) {
                d.push_front(t.top());
                t.pop();
            }
        }
        cout << d.front() << "\n";
    }
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
#define mod 1000000007
int n, p, c, tr;
int main() {
	vector<int> ans;
	int yama[51], tmp[51];
	while (cin >> n >> tr, (n || tr)) {
		for (int i = 0; i <n; ++i) {
			yama[i] = i + 1;
		}
		for (int i = 0; i < tr; ++i) {
			cin >> p >> c;
			for (int j = 0; j < c; ++j) {
				tmp[c-1-j] = yama[n - p - j];
			}
			for (int j = n - p + 1; j < n; j++) {
				yama[j - c] = yama[j];
			}
			for (int j = 0; j < c; j++) {
				yama[n - c + j] = tmp[j];
			}
		}
		ans.push_back(yama[n - 1]);
	}
	for (int i = 0; i < ans.size(); ++i) {
		cout << ans[i] << endl;
	}


	return 0;
}

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

int main(){
  int n,r,c,p;
  vector<int> num(50),ans(50);
  
  while(1){
    cin>>n>>r;
    if(n==0&&r==0)break;
    for(int i=0;i<n;i++) num[n-i-1]=ans[n-i-1]=i+1;
   
    for(int i=0;i<r;i++){
      cin>>c>>p;
      for(int j=0;j<p;j++){      
	int l=0;
	ans[0]=num[c-1];
	for(int k=1;k<n;k++){
	  if(k!=c)ans[k]=num[l];
	  else ans[k]=num[++l];
	  l++;
	}
	for(int k=0;k<n;k++)num[k]=ans[k];
	if(c>=p)for(int m=0;m<p;m++)ans[p-1-m]=num[m];
      }
      //  for(int i=0;i<n;i++)cout<<ans[i]<<endl;
    }
    cout<<ans[0]<<endl;
  }
  
  return 0;
}

C++: #include<stdio.h>

int main() {

	int n, r;
	int array[51];
	int tmp[51];
	while (1) {
		scanf("%d %d", &n, &r);
		if (n == 0 && r == 0) break;

		for (int i = 1; i <= n; i++) {
			array[i] = i;
		}
		for (int i = 0; i < r; i++) {
			int p, c;
			scanf("%d %d", &p, &c);
			for (int j = 0; j < c; j++) {
				tmp[j] = array[n - (p - 1) - j];
			}
			for (int j = 0; j < (p - 1); j++) {
				array[n - (p - 1) - c + 1 + j] = array[n - (p - 1) + 1 + j];
			}
			for (int j = 0; j < c; j++) {
				array[n - c + 1 + j] = tmp[c - 1 - j];
			}
		}
		printf("\n%d\n", array[n]);
	}
}