Go: package main

import "fmt"

func main() {
	var n, r int
	fmt.Scan(&n, &r)
	for n != 0 || r != 0 {
		arr := make([]int, n)
		for i := range arr {
			arr[i] = len(arr) - i
		}

		for i := 0; i < r; i++ {
			var p, c int
			fmt.Scan(&p, &c)
			mid, top, last := arr[:p-1], arr[p-1:p-1+c], arr[p-1+c:]
			arr = append(append(append([]int{}, top...), mid...), last...)
		}
		fmt.Println(arr[0])
		fmt.Scan(&n, &r)
	}
}

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

#define rep(i,N) for(int i=0;i<(int)(N);i++)
#define REP(i,k,N) for(int i=k;i<(int)(N);i++)
#define rrep(i,N) for(int i=N-1;i>=(int)0;i--)

#define vi vector<int>
#define pb push_back

int main(){
//    ifstream in("a_in.txt");
//    cin.rdbuf(in.rdbuf());

    int n,r;
    int cd[51];
    int p,c;
    int tmp[51];
    while(cin>>n>>r,n!=0){
        rep(i,n){
            cd[i]=n-i;
        }
        rep(i,r){
            cin >> p >>c;
            rep(j,c){
                tmp[j]=cd[p+j-1];
            }
            rrep(j,p){
                cd[j+c-1] = cd[j-1];
            }
            rep(j,c){
                cd[j]=tmp[j];
            }

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

    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
  int n, r;
  while(cin >> n >> r, n || r){
    int deck[50];
    for(int i = 0; i < n; i++) deck[i] = n - i;
    while(r--){
      int p, c;
      cin >> p >> c;
      --p;
      int tmp[50];
      for(int i = 0; i < c; i++) tmp[i] = deck[p + i];
      for(int i = p + c - 1; i > 0; i--) deck[i] = deck[i-1];
      for(int i = 0; i < c; i++) deck[i] = tmp[i];
    }
    cout << deck[0] << endl;
  }
  return 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;
}