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 50
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<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

ll v[100];

int main()
{
	cin >> n >> k;
	if (n == 0 && k == 0) {
		return 0;
	} else {
		fill(v, v + 100, 0);
		REP(i, n)
		{
			v[i + 1] = i + 1;
		}
		REP(i, k)
		{
			ll a, b;
			cin >> a >> b;
			ll temp[100];
			REP(j, n + 1) temp[j] = v[j];
			fill(v, v + 100, 0);
			FOR(j, 1, a - b + 1)
			{
				v[j] = temp[j];
			}
			FOR(j, a - b + 1, n + 1 - b)
			{
				v[j] = temp[j + b];
			}
			FOR(j, n - b + 1, n + 1)
			{
				v[j] = temp[j - n + b - 1 + a - b + 1];
			}
		}
	}
	cout << v[n] << endl;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll tmp1[55];

int main(void){
	int n,r;
	while(true){
		cin>>n>>r;
		if(n==0 && r==0)break;
		vector<int>a(n);
		for(int i=0;i<n;i++)a[i]=n-i;
		for(int i=0;i<r;i++){
			int p,c;
			cin>>p>>c;
			for(int i=p-1;i<p+c-1;i++){
				tmp1[i-p+1]=a[i];
			}
			for(int i=p-2;i>=0;i--){
				a[i+c]=a[i];
			}
			for(int i=0;i<c;i++){
				a[i]=tmp1[i];
			}
		}
		cout<<a[0]<<endl;
	}
    return 0;
}

C++: #include <cstdio>

using namespace std;

int n, r;
int cards[2][51];

int main() {
  while (true) {
    scanf("%d %d", &n, &r);
    if (n == 0 && r == 0) break;
    for (int i=0;i<n;i++) cards[0][i] = n-i;
    for (int i=0;i<r;i++) {
      int p, c;
      scanf("%d %d", &p, &c);
      for (int j=0;j<c;j++) {
        cards[(i+1)&1][j] = cards[i&1][p-1+j];
      }
      for (int j=0;j<p-1;j++) {
        cards[(i+1)&1][c+j] = cards[i&1][j];
      }
      for (int j=p-1+c;j<n;j++) {
        cards[(i+1)&1][j] = cards[i&1][j];
      }
    }
    printf("%d\n", cards[r&1][0]);
  }
}

C++: #include <iostream>
using namespace std;
int n, r;
int p, c;
int a[100], tmp[100];

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

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(u) begin(u),end(u)
#define PB push_back
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

typedef long long int ll;
const int INF = (1<<30) - 1;
const double EPS = 1e-9;
const int MOD = 1000000007;

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);

    int n, r;
    while(cin >> n >> r, n|r){
        vector<int> pile(n);
        for(int i=0; i<n; i++)
            pile[i] = n-i;
        
        for(int _=0; _<r; _++){
            int p, c;
            cin >> p >> c;
            vector<int> t(n);
            for(int i=0; i<c; i++)
                t[i] = pile[p-1+i];
            for(int i=0; i<p-1; i++)
                t[i+c] = pile[i];
            for(int i=p-1+c; i<n; i++)
                t[i] = pile[i];
            pile = t;
        }
        
        cout << pile[0] << endl;
    }
    
    return 0;
}

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

int main(){
	int n,r,card[51];
	while(cin>>n>>r, n&&r){
		for(int i=1;i<=n;i++) card[i]=n+1-i;

		int p,c;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			int head=1;
			for(int j=0;j<c;j++){
				int now=p+j;
				while(head<now){
					swap(card[now],card[now-1]);
					now--;
				}
				head++;
				//for(int k=1;k<=n;k++)cout<<card[k]<<":";
				//cout<<endl;
			}
		}
		cout<<card[1]<<endl;
	}

	return 0;
}

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

struct list{
  int number;
  list *next;
};

void Insertlist(list **ptr, int newnumber);
void Traverselist(list *ptr);


void Insertlist(list ** ptr, int newnumber){
  if( *ptr == NULL || (*ptr)->number < newnumber){
    list *newcell;
    newcell = (list *)malloc(sizeof(list));
    newcell->number = newnumber;
    newcell->next = *ptr;
    *ptr = newcell;
  }else{
    Insertlist(&(*ptr)->next, newnumber);
  }
}

void Traverselist(list *ptr){
  while(ptr!= NULL){
    cout << ptr->number << " \n";
    ptr = ptr->next;
  }
}


int main(){

  int n, r;

  while( cin >> n >> r ){

    if( n == 0 && r == 0) break;

    list *root = NULL;
    for(int i = n ; i > 0 ; i--){
      Insertlist(&root,i);
    }
    //       Traverselist(root);    

    while( r ){
      int p,c;
      cin >> p >> c;

      list *ptr1 = root, *ptr2 = root,*ptr3,*ptr4;

	for(int i = 0 ; i < p-2; i++)
	  ptr1 = ptr1->next;
	if(p > 1)
	  ptr2 = ptr1->next;
	ptr3 = ptr2;
	for(int i = 0; i < c-1 ; i++)
	  ptr3 = ptr3->next;
	ptr4 = ptr3->next;

	if(p>1){
	  ptr1->next = ptr4;
	  ptr3->next = root;
	  root = ptr2;
	}
	//   Traverselist(root);    
	r--;
    }
    cout << root->number << endl;
    
  }
}