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 <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(u) begin(u),end(u)
#define PB push_back
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

typedef long long int ll;
const int INF = (1<<30) - 1;
const double EPS = 1e-9;
const int MOD = 1000000007;

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);

    int n, r;
    while(cin >> n >> r, n|r){
        vector<int> pile(n);
        for(int i=0; i<n; i++)
            pile[i] = n-i;
        
        for(int _=0; _<r; _++){
            int p, c;
            cin >> p >> c;
            vector<int> t(n);
            for(int i=0; i<c; i++)
                t[i] = pile[p-1+i];
            for(int i=0; i<p-1; i++)
                t[i+c] = pile[i];
            for(int i=p-1+c; i<n; i++)
                t[i] = pile[i];
            pile = t;
        }
        
        cout << pile[0] << endl;
    }
    
    return 0;
}

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

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

		int p,c;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			int head=1;
			for(int j=0;j<c;j++){
				int now=p+j;
				while(head<now){
					swap(card[now],card[now-1]);
					now--;
				}
				head++;
				//for(int k=1;k<=n;k++)cout<<card[k]<<":";
				//cout<<endl;
			}
		}
		cout<<card[1]<<endl;
	}

	return 0;
}

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

struct list{
  int number;
  list *next;
};

void Insertlist(list **ptr, int newnumber);
void Traverselist(list *ptr);


void Insertlist(list ** ptr, int newnumber){
  if( *ptr == NULL || (*ptr)->number < newnumber){
    list *newcell;
    newcell = (list *)malloc(sizeof(list));
    newcell->number = newnumber;
    newcell->next = *ptr;
    *ptr = newcell;
  }else{
    Insertlist(&(*ptr)->next, newnumber);
  }
}

void Traverselist(list *ptr){
  while(ptr!= NULL){
    cout << ptr->number << " \n";
    ptr = ptr->next;
  }
}


int main(){

  int n, r;

  while( cin >> n >> r ){

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

    list *root = NULL;
    for(int i = n ; i > 0 ; i--){
      Insertlist(&root,i);
    }
    //       Traverselist(root);    

    while( r ){
      int p,c;
      cin >> p >> c;

      list *ptr1 = root, *ptr2 = root,*ptr3,*ptr4;

	for(int i = 0 ; i < p-2; i++)
	  ptr1 = ptr1->next;
	if(p > 1)
	  ptr2 = ptr1->next;
	ptr3 = ptr2;
	for(int i = 0; i < c-1 ; i++)
	  ptr3 = ptr3->next;
	ptr4 = ptr3->next;

	if(p>1){
	  ptr1->next = ptr4;
	  ptr3->next = root;
	  root = ptr2;
	}
	//   Traverselist(root);    
	r--;
    }
    cout << root->number << endl;
    
  }
}

C++: #include <iostream>

using namespace std;

int main(){
  int n, r;
  int card[50];
  int cutp[50];
  int cutc[50];

  while(cin >> n >> r, n || r){
    for(int i=0; i<n; i++){
      card[i] = i+1;
    }
    for(int i=0; i<r; i++){
      int p, c;
      cin >> p >> c;
      for(int i=0; i<p-1; i++){
	cutp[i] = card[n-p+1+i];
      }
      for(int i=0; i<c; i++){
	cutc[i] = card[n-p+1-c+i];
      }
      
      for(int i=0; i<p-1; i++){
	card[n-p+1-c+i] = cutp[i];
      }
      for(int i=0; i<c; i++){
	card[n-p+1+i] = cutc[i];
      }
    }

    cout << card[n-1] << endl;
  }
  return 0;
}

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

int main() {
	int n,r;
	int p,c;
	while(1)
	{
		cin>>n>>r;
		if(n==0||r==0)
		{
			break;
		}
		int i=1;
		int a[n];
		int b[n];
		for(i=0;i<n;i++)
		{
			a[i]=n-i;
			b[i]=0;
		}
	    //cout<<a[0]<<a[1]<<a[2]<<a[3]<<a[4]<<endl;
		i=0;
		while(r!=i)
		{
			cin>>p>>c;
			int j;
			for(j=0;j<c;j++)
			{
				b[j]=a[j+p-1];
			}
			for(j=0;j<p;j++)
			{
				b[c+j]=a[j];
			}
			for(j=0;j<p+c;j++)
			{
				a[j]=b[j];
			}
			i++;
			//cout<<a[0]<<a[1]<<a[2]<<a[3]<<a[4]<<endl;
		}
		cout<<a[0]<<endl;

	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

struct O{int p, c;};
int main()
{
	int n, r;
	while(cin >> n >> r && (n || r))
	{
		stack<O> order;
		rep(i, r)
		{
			O o;
			cin >> o.p >> o.c;
			order.push(o);
		}

		int res = 1;

		for(; !order.empty(); order.pop())
		{
			O o = order.top();

			if(res <= o.c)
				res += o.p - 1;
			else if(res <= o.c + o.p - 1)
				res -= o.c;
		}

		cout << n - res + 1 << endl;
	}
}

C++: // AOJ 1129
#include<iostream>
#include<vector>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

const int NMAX = 100;
int card[NMAX];

int main() {
  int n, r;
  while (cin >> n >> r and n) {
    for (int i = 1; i <= n; i++) {
      card[i] = n + 1 - i;
    }

    REP (R, r) { 
      int p, c;
      cin >> p >> c;
      vector<int> temp1, temp2;
      for (int i = 1; i <= p - 1; i++) {
        temp1.push_back(card[i]);
      }

      for (int i = p; i < p + c; i++) {
        temp2.push_back(card[i]);
      }

      temp2.insert(temp2.end(), temp1.begin(), temp1.end());
      
      for (int i = 0; i < temp2.size(); i++) {
        card[i + 1] = temp2[i];
      }

    }
    cout << card[1] << endl;
  }
}