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 <vector>
#include <algorithm>
using namespace std;

int main() {
  
  while(1){
    
    int n,r,i,j,k;
    cin >>n>>r;
    if (n==0&&r==0)break;
    
    vector<int> nom;
    for(i=0;i<n;i++)
      nom.push_back(n-i);
    
    for(i=0;i<r;i++){
      int p,c;
      cin >>p>>c;
      for(j=0;j<p-1;j++){
	int temp;
	temp = nom[0];
	for(k=0;k<p+c-2;k++)nom[k]=nom[k+1];
	nom[c+p-2] = temp;
      }
    }
    cout << nom[0] <<endl;
    
  }
  return 0;
  
}

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

int main(){
  int n, r;
  while((cin >> n >> r), n,r){
    string s="",t="",u="", v="";
    for(int i=n; i>=1; i--){
      s+=i+'0';
    }
    for(int i=0; i<r; i++){
      int x, y;
      cin >> x >> y;
      t = s.substr(x-1,y);
      u = s.substr(x+y-1,s.length());
      v = s.substr(0,x);
      s = t+v+u;
    }
    int pp = s[0]-'0';
    cout << pp << endl;
  }

  return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

template<typename T> ostream& operator <<(ostream& r, const vector<T> t){vrep(v,t)r<<*v<<(v+1==t.end()?"":" ");return r;}
template<typename T> ostream& operator <<(ostream& r, const pair<vector<T>, int> p){int n=p.second;minup(n,p.first.size());rep(i,n-1)r<<p.first[i]<<' ';r<<p.first[n-1];return r;}
template<typename T> ostream& operator <<(ostream& r, const pair<T*, int> p){int n=p.second-1;rep(i,n)r<<p.first[i]<<' ';return r<<p.first[n];}
template<typename T, size_t S> ostream& operator <<(ostream& r, const T (&a)[S]){rep(i,S-1)r<<a[i]<<' ';return r<<a[S-1];}


int n, r;
int x, y;

int main()
{
  while((cin >> n >> r) && n){
    vi card(n);
    rep(i, n) card[i] = n - i;
    while(r--){
      cin >> x >> y;
      x -= 1;
      vi tmp;
      erep(i, x, x + y) tmp.pb(card[i]);
      rev(i, x) card[i + y] = card[i];
      rep(i, y) card[i] = tmp[i];
    }
    cout << card[0] << endl;
  }

  return 0;
}

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

//?±±?????????????????¢??°???????±±???????±±????????°n???p?????????????????????c???                       
void shuffle(vector<int> &yama, int n, int p, int c);


int main(){
  int n, r;
  int p, c;
  vector<int> yama, v;

  cin >> n;
  cin >> r;

  while(n != 0 && r != 0){
    //?±±??????????????????                                                            
    yama.clear();
    for(int i = 0, j = n; i < n; i++, j--){
      yama.push_back(j);
    }
    //?????£?????????                                                                
    for (int i = 0; i < r; i++){
      cin >> p;
      cin >> c;
      shuffle(yama, n, p, c);
    }
    //???????????????????¨????                                                          
    v.push_back(yama.front());

    cin >> n;
    cin >> r;
  }
  for(int i = 0; i < v.size(); i++){
    cout << v[i] << endl;
  }
}

void shuffle(vector<int> &yama, int n, int p, int c){
  int tmp;

  for(int i = 0;i < c; i++){
    tmp = yama[p-1+c-1];
    yama.erase(yama.begin()+p-1+c-1);
    yama.insert(yama.begin(), tmp);

  }
}

C++: #include<iostream>

using namespace std;

int y[51], t[51];
int n, r;

void set_yama(int n){
    for(int i=0; i<n; i++){
        y[i] = i + 1;
    }
}

void shuffle(int n, int r){
    for(int i=0; i<r; i++){
        int p,c;
        cin >> p >> c;

        for(int j=0; j<c; j++){
            t[c-1-j] = y[n-p-j];
        }

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

        for(int j=0; j<c; j++){
            y[n-c+j] = t[j];
        }
    }
}

int main(void){

    while(1){
        cin >> n >> r;
        if(n==0 || r==0){
            break;
        }
        
        set_yama(n);
        shuffle(n, r);
        cout << y[n-1] << endl;
    }
    return 0;
}

C++: #include <iostream>
#define MAX_R 50
#define MAX_N 50

using namespace std;
void solve();

int c[MAX_R],p[MAX_R],n,r;

int main()
{
    while (1) {
        cin>>n>>r;
        if (n==0&&r==0) break;
        for (int i=0; i<r; i++) cin>>p[i]>>c[i];
        solve();
    }
}

void solve()
{
    int card[MAX_N];
    for (int i=n-1; i>=0; i--) card[i]=n-i;
    for (int i=0; i<r; i++) {
        int cut[MAX_N];
        for (int j=0; j<c[i]; j++) cut[j]=card[p[i]+j-1];
        for (int j=p[i]-2; j>=0; j--) card[j+c[i]]=card[j];
        for (int j=0; j<c[i]; j++) card[j]=cut[j];
    }
    cout<<card[0]<<endl;
}

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

using namespace std;

#define ll long long
#define pb push_back

ll MIN(ll num1,ll num2){
    return num1<num2?num1:num2;
}

int main(){

    while(1){
        int n,r;
        vector<int> P,C,card;
        cin>>n>>r;
        if(n==0&&r==0)break;
        for(int i=n;i>0;i--){
            card.pb(i);
        }
        //for(int j=0;j<n;j++)cout<<card[j]<<" ";
        //cout<<endl;
        for(int i=0;i<r;i++){
            int p,c;
            cin>>p>>c;
            vector<int> tmp;
            for(int j=0;j<c;j++){
                tmp.pb(card[p-1+j]);
                //cout<<card[p-1+j]<<" ";
            }
            //cout<<endl;
            for(int j=0;j<p-1;j++){
                tmp.pb(card[j]);
                //cout<<card[j]<<" ";
            }
            //cout<<endl;
            for(int j=0;j<n-p+1-c;j++){
                tmp.pb(card[p-1+c+j]);
                //cout<<card[p-1+c+j]<<" ";
            }
            //cout<<endl;
            card=tmp;
            //for(int j=0;j<n;j++)cout<<card[j]<<" ";
            //cout<<endl<<endl;
        }
        cout<<card[0]<<endl;
    }

    return 0;
}