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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
using namespace std;
int x[100];
int y[100];
int card [100];
int ans[1000];
int n,r,counter;
bool input(){
	for(int i=0;i<100;i++){
	x[i]=0;
	y[i]=0;
	}
	cin >>n>>r;
	for(int i=0;i<r;i++){
	cin>>x[i]>>y[i];
	}
	if(n==0){
	return false;
	}
	else{
	 return true;
	}
}
void solve(){
	for(int i=0;i<100;i++){
		card[i]=i+1;
	}
	for(int i=0;i<r;i++){
		for(int k=0;k<y[i];k++){
			int a=card[x[i]+y[i]-2];
			for(int j=x[i]+y[i]-1;j>0;j--){
				card[j]=card[j-1];
			}
			card[0]=a;
		}
	}
	ans[counter]=n-card[0]+1;
	counter++;
}



int main (){
	counter=0;
	while(input()){
	solve();
	}
	for(int i=0;i<counter;i++){
	cout<<ans[i]<<endl;
	}
return 0;
}

C++: #include <bits/stdc++.h>
const int INF = 1e9;
const int MODk = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    int n,r;
    while(cin >> n >> r){
        if(n == 0 && r == 0)return 0;
        vector<int> cards(n);
        iota(cards.begin(),cards.end(),1);
        for(int i = 0;i < r;i++){
            int p,c;cin >> p >> c;
            vector<int> vec(n);
            for(int a = 0;a <= n-p-c;a++){
             //   cout<<a<<endl;
                vec.at(a) = cards.at(a);
            }
           // cout<<endl;
            for(int a = n-p-c+1 ;a <= n-(p);a++){
            //    cout<<a<<endl;
                vec.at(a+(p-1)) = cards.at(a);

            }
        //    cout<<endl;
            for(int a = n-p+1;a < n;a++){
          //      cout<<a<<endl;
                vec.at(a-c) = cards.at(a);
            }
            cards = vec;
        }
        cout<<cards.back()<<endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;


int n,r;
main(){
	int i,j,p,c;
	while(cin >> n >> r, n){
		int ans;
		int Deck[51];
		for(i=1;i<=n;i++) Deck[i] = i;
		for(j=1;j<=r;j++){
			cin >> p >> c;
			for(i=1;i<=n;i++){
				if(Deck[i] < p) Deck[i] += c;
				else if(Deck[i] < p+c) Deck[i] -= p-1;
			}
		}
		for(i=1;i<=n;i++){
			if(Deck[i] == 1) break;
		}
		cout << n-i+1 << endl;
	}
	return 0;
}

C++: #include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
  int n,r,p,c;
  int i;
  while(cin >> n >> r && n != 0){
    vector<int> A(n);
    for(i=0;i<n;i++) A[i] = n-i;
    for(i=0;i<r;i++){
      cin >> p >> c;
      rotate(A.begin(),A.begin()+p-1,A.begin()+p+c-1);
    }
    cout << A[0] << endl;
  }
  return 0;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int Card[60];
int temp[60];
int main()
{
  int n,r;
  while(cin >>n>>r,n||r){
  int k = n;
  for(int i = 1; i <=n;i++){
    Card[i] =k--;
  }
  int p,c;
  for(int i = 0;i <r;i++){
    cin>>p>>c;
    int l = 1;
    int m = 1;
    for(int j = 1; j <=p+c-1;j++){
      temp[j] = Card[j];
    }for(int j = p;j <=p+c-1;j++){
      Card[l++] =Card[j];
    }for(int j =1 ;j <=p-1;j++){
      Card[l+j-1] =temp[m++];
    }
  }
  cout <<Card[1]<<endl;
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

int main(void){
	
	int yama[50],temp[50],cut,n,p,c;

	while(cin>>n>>cut,n){
		for(int i=0;i<50;i++){
			yama[i]=0;
			temp[i]=0;
		}
		for(int j=0;j<n;j++){
			yama[j]=n-j;
		}
		for(int i=0;i<cut;i++){
			
			cin>>p>>c;
			
			for(int i=0;i<p-1;i++){
				temp[i]=yama[i];
			}
			for(int i=0;i<c;i++){
				yama[i]=yama[(p-1)+i];
			}
			for(int i=0;i<p-1;i++){
				yama[c+i]=temp[i];
			}
		}
		cout<<yama[0]<<endl;
	}
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	int n,i,j,r,p,c,sum;
	string s;
	vector<int> v,w,x;
	while(1){
		cin>>n>>r;
		if(n==0&&r==0)break;
		
		v.clear();
		w.clear();
		x.clear();
		rep(i,n) v.push_back(i+1);
		rep(j,r){
			
			cin>>p>>c;
			for(i=0;i<n;i++){
				if(i>=n-(p+c-1)&&i<n-(p+c-1)+c) x.push_back(v[i]);
				else w.push_back(v[i]);
			}
			rep(i,x.size()) w.push_back(x[i]);
			v=w;
		//	cout<<v[v.size()-1]<<endl;
			w.clear();
			x.clear();
		//	cout<<"aaaa"<<v.size()<<endl;
		//	rep(i,v.size())cout<<v[i]<<" ";
		//	cout<<endl;
		}
		cout<<v[v.size()-1]<<endl;
	}/*
	5 2
	3 1
	3 1
	v1 2 4 5 3
	if(i>=2&&i<3)
	w1 2 4 5 3
	x3
	*/
	
	
	
//////////////////////////////////////////////////////
return 0;}

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

vector<int> deck;

void swap(int n,int p,int c){
  int tmp[p-1];
  for(int i=0;i<p-1;i++)
    tmp[i]=deck[n-1-i];
  for(int i=0;i<c;i++){
    deck[n-1-i]=deck[n-p-i];
  }
  for(int i=0;i<p-1;i++)
    deck[n-1-c-i]=tmp[i];

}

int main(){
  int n,r,c,p;
  while(cin>>n>>r,n){
      deck.clear();
    for(int i=0;i<n;i++)
      deck.push_back(i+1);
    for(int i=0;i<r;i++){
      cin>>p>>c;
      swap(n,p,c);
    }
    // for(int i=0;i<deck.size();i++)
    //cout<<deck[deck.size() - 1 - i]<<endl;
    //cout<<endl;
    cout<<deck[deck.size()-1]<<endl;
  }
  return 0;
}