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>
#define N 10
using namespace std;
/*
Hanafuda Shuffle
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1129&lang=jp

*/
int array[N];
void makearray(int n){
    for(int i=0;i<N;i++){
	array[i]=n;
	if(n>0)n-=1;
    }
}
void shuffle(int p, int c){
    int sarray[N];
    //copy unshuffled deck
    for(int i=p-1+c;i<N;i++){
	sarray[i]=array[i];
    }
    //copy the c part
    int j=0;
    for(int i=p-1;i<p-1+c;i++){
	sarray[j]=array[i];
	j++;
    }
    // copy the p part
    j=c;
    for(int i=0;i<p-1;i++){
	sarray[j]=array[i];
	j++;
    }
    for(int i=0;i<N;i++){
	array[i]=sarray[i];
    }
}
    
    
    
int main(){
    int n,r, p, c;
    while(1){
	cin >>n>>r;
	makearray(n);
	if(n==0 && r==0)break;
	for(int i=0;i<r;i++){
	    cin >> p>>c;
	    shuffle(p,c);
	}
	cout << array[0] << endl;
    }
    
}

C++: #include<iostream>
using namespace std;
int main(){
int n,r,p,c,huda[51],temp[51],i,j,k,q,s;
while(1){
scanf("%d%d",&n,&r);
if(n==0 && r==0)break;
for(i=1;i<=n;i++)huda[i]=n-i+1;
for(s=0;s<r;s++){
scanf("%d%d",&p,&c);
for(i=1;i<p;i++)temp[i]=huda[i];
for(i=1;i<=c;i++)huda[i]=huda[i+p-1];
for(i=1;i<p;i++)huda[i+c]=temp[i];
}
printf("%d\n",huda[1]);
}
}

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

//?±±?????????????????¢??°???????±±???????±±????????°n???p?????????????????????c???                       
void shuffle(vector<int> &yama, int n, int p, int c);


int main(){
  int n, r;
  int p, c;
  vector<int> yama, v;

  cin >> n;
  cin >> r;

  while(n != 0 && r != 0){
    //?±±??????????????????                                                            
    yama.clear();
    for(int i = 0, j = n; i < n; i++, j--){
      yama.push_back(j);
    }
    //?????£?????????                                                                
    for (int i = 0; i < r; i++){
      cin >> p;
      cin >> c;
      shuffle(yama, n, p, c);
    }
    //???????????????????¨????                                                          
    v.push_back(yama.front());

    cin >> n;
    cin >> r;
  }
  for(int i = 0; i < v.size(); i++){
    cout << v[i] << endl;
  }
  cout << endl;
}

void shuffle(vector<int> &yama, int n, int p, int c){
  int tmp;

  for(int i = 0;i < c; i++){
    tmp = yama[p-1+c-1];
    yama.erase(yama.begin()+p-1+c-1);
    yama.insert(yama.begin(), tmp);

  }
}

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

int main(){
  int n,r;
  int array1[50],array2[50];

  while(1){
    cin>>n>>r;
    if(n+r==0)break;

    for(int i=0;i<n;i++) array1[n-i-1]=array2[n-i-1]=i+1;

    for(int j=0;j<r;j++){
      int c,p;
      cin>>c>>p;

      for(int i=0;i<p;i++){
	swap(array1[c-1+i],array1[i]);
	array2[c-1+i]=0;
      }
      int k=p;
      for(int i=0;i<n;i++){
	while(array2[i]==0) i++;
	array1[k++]=array2[i];
      }
      for(int i=0;i<n;i++){
	//	while(array2[i]==0)i++;
	array2[i]=array1[i];
      }
      //      for(int i=0;i<n;i++) cout<<array1[i]<<endl;     
    }

    cout<<array1[0]<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	int n1,c,p,n, r,y[50],tmp[50];
	while (cin >> n >> r&&n&&r) {
		n1 = n;
		for (int i = 0; i < n; i++) {
			y[i] = n1--;
			//cout << y[i] << ' ';
		}//cout << endl;
		
		for (int j = 0; j < r; j++) {
			cin >> p >> c;
			for (int k = 0; k < p-1; k++) {
				tmp[k] = y[k];
			}
			for (int i = 0; i < c; i++) {
				y[i] = y[p-1 + i];
			}
			for (int l = 0; l < p-1; l++) {
				y[c + l] = tmp[l];
			}
			//for (int i = 0; i < n; i++)cout << ' ' << y[i]; cout << endl;
		}
		cout << y[0] << endl;
	}
}

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


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

    deque<int> card;
    for(int i=1;i<n+1;i++){
      card.push_back(n-i+1);
    }
    for(int i=0;i<r;i++){
      int p,c;
      cin >> p >> c;
      for(int j=0;j<c;j++){
	card.push_front( card[p+c-2] );
	deque<int>::iterator ite = card.begin()+p+c-1; 
	card.erase( ite );
      }
    }
    cout << card[0] << endl;
  }
  return 0;
}

C++: #include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;

/** Problem1129 : Hanafuda Shuffle **/
int main()
{
	vector<int> card;
	int n, r, p, c;
	
	while (cin >> n >> r, n||r) {
		card.clear();
		rep(i, n)
			card.push_back(n-i);
		
		rep(k, r) {
			cin >> p >> c;
			vector<int> tmp;
			rep(i, c)
				tmp.push_back(card[i+p-1]);
			rep(i, p-1)
				tmp.push_back(card[i]);
			REP(i, p+c-1, n) {
				tmp.push_back(card[i]);
			}
			card = tmp;
		}
		cout << card[0] << endl;
	}
	return 0;
}

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

int main(){
  int n,r, start, end;
  vector<int> ans;
  cin >> n >> r;
  while(n||r){
    vector<int> data(n);
    for(int i = 0; i <n;i++){
      data[i] = n-i;
    }
    for(int j = 1; j <= r ; j++){
      cin >> start >> end;
      for(int k = 0; k < end;k++){
        int a = data[start+k-1];
        for(int forth = start-1; forth > k; forth--){
          data[k+forth] = data[k+forth-1];
        }
        data[k] = a;
      }
    }
    ans.push_back(data[0]);
    cin >> n >> r;
  }
  for(int i =0;i<ans.size();i++){
    cout << ans[i] << endl;
  }
}

C++: #include <iostream>
#include <math.h>
using namespace std;


int main(void){
    while (1) {
        int n, r;
        cin >> n >> r;
        if (n == 0 && r == 0) return 0;
        
        int m[55];
        for (int i = 0; i < n; i++) m[n - 1 - i] = i;
        
        for (int i = 0; i < r; i++) {
            int p, c;
            cin >> p >> c;
            
            int tmp[55];
            for (int j = 0; j < p - 1; j++) tmp[j] = m[j];
            
            for (int j = 0; j < c; j++) m[j] = m[p - 1 + j];
            
            for (int j = 0; j < p - 1; j++) m[c + j] = tmp[j];
            
        }
        
        cout << m[0] + 1 << endl;
    }
}