Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		n, _ := strconv.Atoi(chunks[0])
		r, _ := strconv.Atoi(chunks[1])
		cards := make([]int, n, n)
		for i := 0; i < n; i++ {
			cards[i] = n - i
		}
		for i := 0; i < r; i++ {
			sc.Scan()
			chunks := strings.Split(sc.Text(), " ")
			p, _ := strconv.Atoi(chunks[0])
			c, _ := strconv.Atoi(chunks[1])
			block := make([]int, c, c)
			for j := 0; j < c; j++ {
				block[j] = cards[p+j-1]
			}
			for j := p - 2; j >= 0; j-- {
				cards[j+c] = cards[j]
			}
			for j := 0; j < c; j++ {
				cards[j] = block[j]
			}
		}
		fmt.Println(cards[0])
	}
}

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

int main() {
  for(int n, r; cin >> n >> r && (n|r); ){
    deque<int> deq;
    for(int i = 0; i < n; ++i) deq.push_front(i+1);
    for(int i = 0; i < r; ++i) {
      int p, c;
      cin >> p >> c;
      --p;
      deque<int> tmp(deq.begin() + p, deq.begin() + (p+c));
      deq.erase(deq.begin() + p, deq.begin() + (p+c));
      for(int j = (int)tmp.size()-1; j >= 0; --j) deq.push_front(tmp[j]);
    }
    cout << deq.front() << endl;
  }
  return 0;
}

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

using namespace std;

int top_search(int,int,int,int *);
int main(){
	int n,r,c,p;
	int cnt=0;
	int top[51];
	while(1){
		cin>>n>>r;
		if(n==0&&r==0)
			break;
		int *hanahuda=new int[n];

		for (int i = n-1; i>=0 ; i--)
			hanahuda[i]=n-i;

		for(int i=0;i<r;i++){
			cin>>p>>c;
			top[cnt]=top_search(n,p,c,hanahuda);
		}
		delete[] hanahuda;
		cnt++;
	}
	for(int m=0;m<cnt;m++)
		cout<<top[m]<<endl;
	return 0;
}
int top_search(int n,int p,int c,int *hanahuda){
	int cnt=0;
	for(int k=p-1;k<p+c-1;k++){

		int nokori=hanahuda[k];

		for(int l=p-2;l>=0;l--)
			hanahuda[l+1]=hanahuda[l];


		hanahuda[cnt]=nokori;
		cnt++;
	}

	return *hanahuda;
}

C++: #include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;

int main(){
	int n,r;
	while(cin>>n>>r&&n){
		stack<int> st,tmp1,tmp2;
		int p,c;
		REP(i,1,n+1){
			st.push(i);
		}
		REP(i,0,r){
			cin>>p>>c;
			REP(j,0,p-1){
				tmp1.push(st.top());
				st.pop();
			}
			REP(j,0,c){
				tmp2.push(st.top());
				st.pop();
			}
			while(!tmp1.empty()){
				st.push(tmp1.top());
				tmp1.pop();
			}
			while(!tmp2.empty()){
				st.push(tmp2.top());
				tmp2.pop();
			}
		}
		p(st.top());
	}

	return 0;
}

C++: #include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
// int dx[]={0,1,0,-1,1,-1};
// int dy[]={1,0,-1,0,1,-1};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}
void printvi(vector<int> v){rep(i,0,v.size()){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
void printvil(vector<int> v){rep(i,0,v.size()){cout<<v[i]<<endl;}}
void printvvi(vector<vector<int>> v){
    rep(i,0,v.size()){
        rep(j,0,v[i].size())cout<<v[i][j];
        cout<<endl;
    }
}
void printvstr(vector<string> v){
    rep(i,0,v.size()){
        cout<<v[i]<<endl;
    }
}

signed main (){
    int n,r;
    while(1){
        cin>>n>>r;
        if(n+r==0)break;
        vector<int> v(n);
        rep(i,0,n)v[i]=i+1;
        rep(i,0,r){
            int p,c;
            cin>>p>>c;
            vector<int> P,C;
            rep(j,0,p-1){
                P.emplace_back(v.back());
                v.erase(v.end()-1);
            }
            //printvi(P);
            rep(j,0,c){
                C.emplace_back(v.back());
                v.erase(v.end()-1);
            }
            //printvi(C);
            reverse(all(P));
            reverse(all(C));
            rep(j,0,p-1){
                v.emplace_back(P[j]);
            }
            rep(j,0,c){
                v.emplace_back(C[j]);
            }
            //printvi(v);
        }
        cout<<v.back()<<endl;
    }
    
}
/*
FRCFCRF
*/

C++: #include <stdio.h> 
#include <stdlib.h> 

int main(){ 

	int n,r,i,j,p,k,c,a=0; 

	int data[1000],buff[1000],answer[1000]; 

	while(1){ 

 		scanf("%d",&n);
	 	scanf("%d",&r);


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

		for(i=n;i>0;i--){ 
		data[n-i]=i;	
		} 

		for(j=0;j<r;j++){ 

 
 		scanf("%d",&p);
 		scanf("%d",&c);
 

		p--; 
		c=p+c-1;


			for(i=p,k=0;i<=c;i++,k++){ 
			buff[k] = data[i]; 
			} 


		i = 0; 
			while(i < p){ 
			buff[k] = data[i]; 
			k++; 
			i++; 
			} 


		i=c+1; 
			while(i < n){ 
buff[k] = data[i]; 
k++;	
i++; 
} 


for(i=0;i<n;i++){ 
data[i] = buff[i]; 
} 
} 

answer[a] = data[0];
 a++;
} 
 for(i=0;i<a;i++){
 printf("%d\n",answer[i]);
}




return 0; 
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n,r;
  while(true){
    cin >> n >> r;
    if(n==0) break;
    int p,c;
    int now[n+1],pre[n+1];
    for(int i=1;i<=n;i++) pre[i]=n-i+1;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      for(int j=1;j<=c;j++) now[j]=pre[j+p-1];
      for(int j=c+1;j<=p+c-1;j++) now[j]=pre[j-c];
      for(int j=p+c;j<=n;j++) now[j]=pre[j];
      for(int j=1;j<=n;j++) pre[j]=now[j];
    }
    cout << now[1] << endl;
  }
}