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 <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (typeof((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(typeof(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



int main() {
    //freopen( "/Users/macuser/Documents/Programming/Contest/input.in", "r", stdin );
    int n, r;
    while (cin >> n >> r) {
        if (n == 0) break;
        
        deque<int> hana(n);
        for (int i = 0; i < n; ++i) hana[i] = n-i;
        for (int i = 0; i < r; ++i) {
            int c, p;
            cin >> p >> c;
            vint temp;
            for (int k = 0; k < c; ++k) {
                temp.PB(hana[p-1]);
                hana.erase(hana.begin()+p-1);
            }
            reverse(ALL(temp));
            for (int k = 0; k < c; ++k) {
                hana.push_front(temp[k]);
            }
            
            //for (int i = 0; i < n; ++i) cout << hana[i] << ","; cout << endl;
        }
    
        cout << hana[0] << endl;
    }
    
    return 0;
}

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

int main(void){
  vector<int> f;
  while(1){
    f.clear();
    int n, r, p, c;
    cin >> n >> r;
    if(n == 0 && r == 0) return 0;
    for(int i=n; i > 0; i--){
      f.push_back(i);
    }


    vector<int> t;
    for(int i=0; i < r; i++){
      cin >> p >> c;
      t.clear();
      for(int j=p-1; j < p+c-1; j++){
        t.push_back(f.at(j));
      }
      for(int j=p-1; j > 0; j--){
        f.at(j+c-1) = f.at(j-1);
      }
      for(int j=0; j < c; j++){
        f.at(j) = t.at(j);
      }


    }
    cout << f.front() << endl;
  }
}

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

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

		for(int j=0; j<r; j++){
			int p,c;
			cin >> p >> c;

			vector<int> change;

			for(int i=p-1; i<p-1+c; i++){
//				cout << "step1 " << card[i] << endl;
				change.push_back(card[i]);
			}
			for(int i=0; i<p-c; i++){
//				cout << "step2 " << card[i] << endl;
				change.push_back(card[i]);
			}
			
			int count=0;
			vector<int>::iterator it = change.begin();
			while(it!=change.end()){
				card[count] = *it;
				count++;
				it++;
			}
			
		}
		cout << card[0] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS

    while(true) {
        int n, r;
        cin >> n >> r;
        if (n == 0) break;
        vector<int> v(n);
        iota(RALL(v),1);
        REP(i,r) {
            int p, c;
            cin >> p >> c;
            p--;
            vector<int> tmp(v.begin()+p,v.begin()+p+c);
            tmp.insert(tmp.end(),v.begin(),v.begin()+p);
            tmp.insert(tmp.end(),v.begin()+p+c,v.end());
            swap(v,tmp);
        }
        cout << v[0] << endl;
    }

    return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n,r;
  while(1){
    cin >> n >> r;
    if(n==0) return 0;
    vector<int> card(n);
    vector<int> tmp(n);
    for(int i=0;i<n;i++){
      card[i]=n-i;
    }
    int p,c;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      p--;
      for(int i=0;i<p;i++){
        tmp[i]=card[i];
      }
      for(int i=0;i<c;i++){
        card[i]=card[p+i];
      }
      for(int i=0;i<p;i++){
        card[c+i]=tmp[i];
      }
    }
    cout << card[0] << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;
int b[50],a[50];
int n,r,p,c;
void sol();
int main(){
	while (1){
		cin >> n >> r;
		if (n==0 && r==0) 	return 0;
		for(int i= 0;i<n;i++){
			b[i] = i+1;
		}

		for(int i=0;i<r;i++){
			cin >> p >> c ;
			sol();
			for(int i= 0;i<n;i++){
			//	cout << b[i] << " " << a[i] <<endl;
				b[i] = a[i];
				
			}				
		}
		cout << a[n-1] << endl;
	}

}

void sol(){
	for(int i= 0;i<n-p-c+1;i++){
		a[i]=b[i];
	}
	for(int i=n-p-c+1;i<n-c;i++){
		a[i]=b[c+i];
	}
	for(int i=n-c;i<n;i++){
		a[i]=b[i-p+1];
	}
}

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

int main(){

    int n,cu; 

    int rea[50],ano[50];

    while(1){

        cin>>n>>cu;

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

        for(int i=0; i<n; i++) rea[i] = n-i;

        for(int i=0; i<cu; i++){

            int p,num; cin>>p>>num;

            for(int j=0; j<n; j++) ano[j] = rea[j];

            for(int j=0; j<p-1; j++) ano[ j + num] = rea[j];

            for(int j=0; j<num; j++) ano[j] = rea[j+p-1];

            for(int j=0; j<n; j++) rea[j] = ano[j];
        }

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

    return 0;
}

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

int main(int argc, char const *argv[])
{
	int n,r;
	while(cin>>n>>r,n+r)
	{
		int a[n],b[n];
		for (int i = 0; i < n; ++i) a[i]=n-i;
		int p,c;
		for (int i = 0; i < r; ++i)
		{
			cin>>p>>c;
			--p;
			for (int i = 0; i < n; ++i) b[i]=a[i];
			for (int i = 0; i < c; ++i) a[i]=b[i+p];
			for (int i = 0; i < p; ++i) a[i+c]=b[i];
		}
		cout<<a[0]<<endl;
	}
	return 0;
}