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++: //
//  main.cpp
//  no.3
//
//  Created by MacBook_Virgo on 2015/05/12.
//  Copyright (c) 2015??´ MacBook_Virgo. All rights reserved.
//

#include <iostream>
#define rep(i,n) for(int (i) = 0;(i) < (n); (i)++)
using namespace std;
int n,r,p,c;
int main(int argc, const char * argv[]) {
    while(cin >> n >> r,(n!=0)||(r!=0)){
        int A[2][60];
        rep(i,n){
            A[0][i] = n-i;
        }
        int now = 0;
        int next = 1;
        rep(i,r){
            cin >> p >> c;
            rep(j,c){A[next][j]=A[now][p-1+j];}
            for(int j = p+c-1; j < n; j++){
                A[next][j] = A[now][j];}
            for(int j = c; j<c+p-1; j++){
                A[next][j] = A[now][j-c];}
            int temp;
            temp = now;
            now = next;
            next = temp;
            
        }
        cout << A[now][0] << endl;
    }
    
    return 0;
}

C++: #include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>


#define mp(a,b) make_pair(a,b)
#define rep(i,n) for (size_t i = 0; i < (n); ++i)
typedef long long ll;


using namespace std;
int main(){
  int n,r;
  while(cin >> n >> r and (n bitor r) != 0){
    string s;
    for (int i = n; i > 0; --i)  s.push_back(i+'0');
    int p,c;
    for(int i = 0;i < r;i++){
      cin >> p >> c;
      s = s.substr(p-1,c) + s.substr(0,p-1)
	+ s.substr(p+c-1);
    }
    cout << (int)(s[0] - '0') << endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
  
int main()
{
	int n,m;
	int p[51]={0};
	int c[51]={0};
	int i;
	int ans;

	while(1)
	{
	scanf("%d %d",&n,&m);
	if((n==0)&&(m==0))
		break;
	ans=n;

	for(i=1;i<=m;i++){
		scanf("%d %d",&p[i],&c[i]);	
	}

	for(i=m;i>=1;i--){
		if(p[i]!=1){
		if((n-p[i]+1-c[i])>ans){
		}else if(ans>=(n-c[i]))
			ans = ans-p[i]+1;
		else
			ans = ans+c[i];
		}
	}
	printf("%d\n",ans);

	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
	vector<int> v;
	while(1){
		v.clear();
		int n,r;
		cin>>n>>r;
		if(n==0&&r==0)break;
		for(int i=n;i>0;i--){
			v.push_back(i);
		}
		vector<int> q;
		for(int i=0;i<r;i++){
			q.clear();
			int p,s;
			cin>>p>>s;
			p--;
			for(int j=p;j<p+s;j++)
				q.push_back(v[j]);
			for(int j=p-1;j>=0;j--)
				v[s+j]=v[j];
			for(int j=0;j<s;j++)
				v[j]=q[j];

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

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

int main() {
	int n,r;//1~50
	int p,c;
	int card[50]={};
	int cut[50]={};
	int i,j;
	int finish=0;
	
	scanf("%d%d",&n,&r);
	while(finish==0){
	for(i=0;i<n;i++){
		card[i]=n-i;
//		printf("0\t %d\n",card[i]);
	}
	for(j=0;j<r;j++){
		scanf("%d%d",&p,&c);
		for(i=0;i<c;i++){
			cut[i]=card[p+i-1];
//			printf("1\t %d\n",cut[i]);
		}
		for(i=p-2;i>-1;i--){
			card[i+c]=card[i];
//			printf("2\t %d\n",card[i]);
		}
		for(i=0;i<c;i++){
			card[i]=cut[i];
		}
	}
//	for(i=0;i<n;i++){
//		printf("3\t %d\n",card[i]);
//	}
	printf("%d\n",card[0]);
	scanf("%d%d",&n,&r);
	if((n==0)&&(r==0)){finish=1;}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
typedef pair<int,int> P;

int main() {
  int n,m;
  while(cin >> n >> m && (n||m)) {
    int a[n];
    rep(i,n) a[i]=n-i;
    rep(i,m) {
      int p,c;
      cin >> p >> c;
      rep(j,c) {
	for(int k=j+p-1; k>j; k--) swap(a[k],a[k-1]);
      }
    }
    pr(a[0]);
  }
  return 0;
}

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

int N,R;
int D[2][55];
int main(){
  while( cin >> N >> R  && ( N|| R) ){
    for(int i=0;i<N;i++) D[0][i] = i+1;
    for(int i=0;i<R;i++){
      int P,C;
      cin >> P >> C;
      int in = N - (P-1) - C;
      for(int j=0;j<in;j++) D[1][j] = D[0][j];
      for(int j=0;j<C;j++){
	D[1][in+(P-1)+j] = D[0][in+j];
      }
      for(int j=0;j<P-1;j++){
	D[1][in+j] = D[0][in+C+j];
      }
      for(int j=0;j<N;j++){
	D[0][j] = D[1][j];
	//	cout << D[0][j] << " ";
      }
      //      cout << endl;
    }
    cout << D[0][N-1] << endl;
  }
}

C++: #include<iostream>
#include<queue>
using namespace std;
int main(){

  int p,c,n,r,fuda[50];
  queue<int> shuffle;

  while(1){

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

  for(int i=0 ; i < 50  ; i++){
    fuda[i]=i+1;
  }
  
  for(int i=0 ; i < r ; i++){
    
    cin >>p>>c;
    
    for(int j=n-p+1 ; j < n ; j++){ 
      shuffle.push(fuda[j]);
    }
    for(int j=n-p+1-c ; j < n-p+1; j++){
      shuffle.push(fuda[j]);
    }
    for(int j=n-p+1-c ; j < n ; j++){
     fuda[j] = shuffle.front();
      shuffle.pop();
    }
    
  }
  
  cout << fuda[n-1]<<endl;;
  
  }

  return 0;
}

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

int main(){
	while(1){
		int n, r;
		int card[51]; //1~nを使う
		
		scanf(" %d %d", &n, &r);
		if(n==0 && r==0) break; 
		for(int i=1; i<=n; ++i) card[i]=n+1-i;
	
		for(int i=0; i<r; ++i){
			int p, c;
			scanf(" %d %d", &p, &c);
			
			int tmp[50];
			for(int j=0; j<c; ++j) tmp[j]=card[p+j];
			for(int j=p-1; j>0; --j) card[j+c]=card[j];	
			for(int j=1; j<=c; ++j) card[j]=tmp[j-1];
			
			//for(int i=1; i<=n; ++i) printf(" %d",card[i]);
			//printf("\n");
		}
		printf("%d\n", card[1]);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
    int n,r;
    cin>>n>>r;
    if(n==0 && r==0) break;
    int a[51]={};
    for(int i=1;i<=n;i++){
      a[i]=n-i+1;
    }
    for(int i=0;i<r;i++){
      int p,c;
      cin>>p>>c;
      for(int j=1;j<=c;j++){
	for(int k=1;p+c-k>0;k++){
	  if(p+c-k>1)swap(a[p+c-k-1],a[p+c-k]);
	}
      }
    }
    cout<<a[1]<<endl;
  }
  return 0;
}