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 <iostream>
#include <utility>
#include <string>
using namespace std;

int main(void){
  while(1){
    int n, r;
    cin >> n;
    cin >> r;
    if(n == 0 && r == 0){return 0;}

    int f[n];
    for(int i = 0 ; i < n ; i++){
      f[i] = n - i;
    }

    int p[r];
    int c[r];
    for(int i = 0 ; i < r ; i++){cin >> p[i]; cin >> c[i];}


    for(int i = 0 ; i < r ; i++){
      int tempu[p[i]-1];
      int tempd[c[i]];
      for(int j = 0 ; j < p[i]-1 ; j++){
        tempu[j] = f[j];
      }
      for(int j = 0 ; j < c[i] ; j++){
        tempd[j] = f[j + p[i] -1];
      }
      for(int j = 0 ; j < c[i] ; j++){
        f[j] = tempd[j];
      }
      for(int j = 0 ; j < p[i]-1 ; j++){
        f[j+c[i]] = tempu[j];
      }
    }

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

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
using namespace std;

int n,r,p,c;
int before[50],after[50],tmp[50];

void init(){
	for(int i=0;i<50;i++)
		after[i]=tmp[i]=0;
}

bool input(){	
	int i;
	cin>>n;
	cin>>r;
	if((n==0) && (r==0))
		return false;
	for(i=0;i<n;i++)
		before[i]=n-i;	
	return true;
}

void Shuffle(int b[], int a[], int t[]){
	int j;
	for(j=0;j<c;j++){
			a[j]=b[p-1+j];
			t[j]=b[p-1+j];
		}
		for(j=0;j<p;j++){
			a[c+j]=b[j];
			t[c+j]=b[j];
		}
		for(j=0;j<n;j++)
			b[j]=t[j];
}


int solve(){
	for(int i=0;i<r;i++){
		cin>>p>>c;
		Shuffle(before,after,tmp);
	}
	return after[0];
}


int main(){
  while(init(),input()){
	cout<<solve()<<endl;
  }
  return 0;
}

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

class Hanafuda
{
  public:
    Hanafuda(int size);
    ~Hanafuda();
    void Shuffle(int p, int c);
    int Top();

  private:
    int* m_hanafuda;
    int m_size;
};

Hanafuda::Hanafuda(int size)
{
  m_size = size;
  m_hanafuda = new int[m_size];
  for (int i = 0; i < m_size; ++i)
  {
    m_hanafuda[i] = m_size - i;
  }
}

Hanafuda::~Hanafuda()
{
  delete[] m_hanafuda;
}

void Hanafuda::Shuffle(int p, int c)
{
  int* buf_p = new int[p-1];
  int* buf_c = new int[c];

  copy(m_hanafuda, m_hanafuda + p  - 1, buf_p);
  copy(m_hanafuda + p - 1, m_hanafuda + p - 1 + c, buf_c);
  
  copy(buf_c, buf_c + c, m_hanafuda);
  copy(buf_p, buf_p + p - 1, m_hanafuda + c);
}

inline int Hanafuda::Top()
{
  return m_hanafuda[0];
}

int main(void)
{
  while (true)
  {
    int n, r;
    cin >> n >> r;
    if ( n == 0 and r == 0 ) break;

    Hanafuda hanafuda(n);

    int p, c;
    for (int i = 0; i < r; ++i)
    {
      cin >> p >> c;
      hanafuda.Shuffle(p, c);
    }

    cout << hanafuda.Top() << endl;
  }
  return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1129&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

int n,r;

ll solve(){
    vector<int> s(n);
    iota(s.begin(),s.end(),1); reverse(s.begin(), s.end());
    for(int i = 0; i < r;i++){
        int a,b; cin >> a >> b; a--;
        vector<int> s1(s.begin()+a,s.begin()+a+b),s2(s.begin(),s.begin()+a),s3(s.begin()+a+b,s.end());
        s.clear();
        for(auto v:s1) s.push_back(v);
        for(auto v:s2) s.push_back(v);
        for(auto v:s3) s.push_back(v);
    }
    return *s.begin();
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> n >> r,n|r){
        cout << solve() << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>

int testcase_ends() {
  size_t n, r;
  scanf("%zu %zu", &n, &r);
  if (n == 0 && r == 0) return 1;

  std::vector<int> a(n);
  std::iota(a.begin(), a.end(), 1);
  std::reverse(a.begin(), a.end());

  for (size_t i = 0; i < r; ++i) {
    size_t p, c;
    scanf("%zu %zu", &p, &c);
    --p;
    std::vector<int> a0(a.begin()+p, a.begin()+p+c);
    std::vector<int> a1(a.begin(), a.begin()+p);
    a0.insert(a0.end(), a1.begin(), a1.end());
    for (size_t j = 0; j < a0.size(); ++j) a[j] = a0[j];
  }
  printf("%d\n", a[0]);
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}

C++: #include <iostream>

#define rep(i, m) for(int i=0; i<m; i++)

int main(void){

	int n, r;		//山の枚数、回数
	int p, c;		//上からの何枚目、枚数
	int n1[50];	//山
	int temp[50];	//一時的に保存しておく
	int ans[50];	//答えを保存しておく
	int j=0;		//答えを格納する時に使う

	while(std::cin >> n >> r, n || r){		//n,rを取得０、０でなければループ

		rep(i,n){
			n1[i] = n-i;						//n1[n] = {n,n-1,n-2,.........,1}
		}

		rep(i,r){

			std::cin >> p >> c;				//p,cを取得
			rep(i, c){
				temp[i] = n1[p-1+i];
			}
			rep(i, p-1){
				n1[p-1-i+c] = n1[p-1-i];
			}

			rep(i,c){
				n1[i] = temp[i];
			}
		}
		std::cout << n1[0] << std::endl;
		//ans[j++] = n1[0];
	}

	/*
	rep(i,j){
		std::cout << ans[i] << std::endl;
	}
	*/
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, r, p, c;
V v;

int main(){
	while (cin >> n >> r&&n + r){
		REP(i, n){
			v.push_back(n - i);
		}
		REP(i, r){
			cin >> p >> c;
			V t;
			REP(i, c){
				t.push_back(v[p - 1 + i]);
			}
			REP(i, p - 1){
				t.push_back(v[i]);
			}
			FOR(i, p - 1 + c, n){
				t.push_back(v[i]);
			}
			cout << endl;
			v = t;
		}
		cout << v[0] << endl;
		v.clear();
	}
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int t[55][55];
int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	while(cin>>n>>m){
		if(!n)break;
		memset(t,0,sizeof(t));
		for(i=0;i<n;i++)t[0][i]=n-i;
		for(i=0;i<m;i++){
			cin>>a>>b;
			for(j=0;j<n;j++){
				if(j<b)t[i+1][j]=t[i][a+j-1];
				else if(j<a+b-1)t[i+1][j]=t[i][j-b];
				else t[i+1][j]=t[i][j];
			}
		}
		cout<<t[m][0]<<endl;
	}
}