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++: // ・AOJ1142(setの練習問題)
// ・AOJ1129(vectorの練習問題)
// ・AOJ10032(stackの練習問題)
// ・AOJ10027(stringの練習問題)
// ・AOJ10021(sort || priority_queueの練習問題)
// ・AOJ1064(オーバーロードの練習問題)
// ・AOJ0138(mapの練習問題)
// ・AOJ0105(mapの練習問題)
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int main() {
	int n, r, p, c;
	vector<int> v;
	vector<int>::iterator ite;
	while(1){
		scanf("%d%d", &n, &r);
		if(n ==0 && r == 0) break;
		for (int i=1; i<=n; i++) { v.push_back(i); }
		for (int i=0; i<r; i++) {
			scanf("%d%d", &p, &c);
			ite = v.end()-p-c+1;
			for(int j=0; j<c; j++) {
				v.push_back(*ite);
				v.erase(ite);
			}
		// vector<int>::iterator test;
		// test = v.begin();
		// while(test != v.end()){printf("%d", *test); test++;}
		// printf("\n");
		// }
		ite = v.end()-1;
		printf("%d\n", *ite);
	}
}

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

int main() {

  int n, r;
  int card[64];
  int card2[64];
  int p, c;

  for(;;) {
    std::cin >> n >> r;
    if( n == 0 && r == 0 ) {
      break;
    }

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

    for(int i = 0; i < r; ++i) {
      std::cin >> p >> c;

      for(int j = 0; j < p-1; ++j) {
	card2[j+c] = card[j];
      }

      for(int j = p-1; j < c+p-1; ++j) {
	card2[j-p+1] = card[j];
      }

      for(int j = 0; j < c+p-1; ++j) {
	card[j] = card2[j];
      }
    }
    std::cout << card[0] << std::endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <vector>

using namespace std;

int solve(int n,int r)
{
	if(r==0) return n;
	int p,c; cin>>p>>c;
	int x=solve(n,r-1);
	if(x>n-c)
		x-=(p-1);
	else if(n-p-c<x && x<=n-c)
		x+=c;
	return x;
}

int main()
{
	for(int n,r;cin>>n>>r,n|r;)
		cout<<solve(n,r)<<endl;
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
const double PI=acos(-1.0);
//---------------------------------------------------------------------------//
int n,r;
int a[51],b[51],c[51];
int main(){
        while(1) {
                cin>>n>>r;
                if(n==0 && r==0) {
                        return 0;
                }
                for(int i=0; i<r; i++) {
                        cin>>a[i]>>b[i];
                }

                for(int i=0; i<n; i++) {
                        c[i]=i;
                }
                for(int i=0; i<r; i++) {
                        for(int j=0; j<a[i]-1; j++) {
                                c[j]+=b[i];
                        }
                        for(int j=a[i]-1; j<a[i]-1+b[i]; j++) {
                                c[j]-=(a[i]-1);
                        }
                }
                for(int i=0; i<n; i++) {
                        if(c[i]==0) {
                                cout<<n-i<<endl;
                                return 0;
                        }
                }
        }
}

C++: #include<iostream>
using namespace std;
int main(){
	int huda[101];
	int n,r;
	while(cin>>n>>r,n||r){
	int p,c;
	for(int i=0;i<101;i++)huda[i]=i+1;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			for(int j=n-p-c+1;j<n-p+1;j++){
				//for(int x=0;x<n;x++)cout<<huda[x]<<" ";cout<<endl;
				int tmp=huda[n-p-c+1];
				for(int k=n-p-c+1;k<n-1;k++){
					huda[k]=huda[k+1];
				}
				huda[n-1]=tmp;
			}
		}
		cout<<huda[n-1]<<endl;
		for(int fjl=0;fjl<101;fjl++)huda[fjl]=0;
	}
	return 0;
}

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

int main(){
	int n,r,p,c;
	while(true){
		vector<int> a,b;
		cin >> n >> r;
		if(n==0 && r == 0)	break;
		a.resize(n);b.resize(n);
		for(int i = 0; i < n; ++i){
			a[i] = i;
		}
		for(int  i = 0; i < r; ++i){
			cin >> p >> c;

			for(int j = n-p-c+1; j < n; ++j){
				b[j] = a[j];
			}
			for(int j = n-p-c+1; j < n-p+1; ++j){
				a[j+p-1] = b[j];
			}
			for(int j = n-p+1; j < n; ++j){
				a[j-c] = b[j];
			}
		}
		cout << a[n-1]+1 << endl;
	}
}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;


int main(void) {
	
	while (1) {
		int n, r;
		int p, c;
		int a[51] = {};
		int b[51] = {};
		FOR(i, 1, n) {
			a[i] = n - i + 1;
		}
		cin >> n >> r;
		if (n == 0 && r == 0) {
			break;
		}
		FOR(i, 1, r) {
			cin >> p >> c;
			FOR(t, 1, p - 1) {
				b[t] = a[t];
			}
			FOR(t, 1, c) {
				a[t] = a[p + t - 1];
			}
			FOR(t, 1, p - 1) {
				a[p + t - 1] = b[t];
			}
		}
		cout << a[1] << endl;
	}

}

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

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
	int n, r;
	int card[55];
	int a[55], b[55];
	while(cin >> n >> r, n+r){
		rep(i, n) card[i] = n-i;
		int p, c;
		for(int i=0; i< r; i++){
			cin >> p >> c;

			rep(i, p) a[i] = card[i];
			rep(i, c) b[i] = card[p+i-1];
			rep(i, c) card[i] = b[i];
			rep(i, p) card[i+c] = a[i];

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

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

using namespace std;

int cards[55],n;

void init(){
	int i;
	for(i=0; i<n; i++){
		cards[i+1] = (n-i);
	}
}

void shuffle(int p,int c){
	int tmp[55],i;
	for(i=1; i<=n; i++){
		tmp[i] = cards[i];
	}
	for(i=0; i<c; i++){
		cards[i+1] = tmp[p+i];
	}
	for(i=1; i<p; i++){
		cards[c+i] = tmp[i];
	}
}

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

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

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

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);
  }
}

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);
    }
 
    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;
      } 
      r--;
    }
    cout << root->number << endl;
  }
  return 0;
}