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>
using namespace std;

int main(){

  int card[50];
  int esc[50];
  int n,r;
  int p,c;

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

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

      //cout << "prev:";
      //for(int j=0; j<n; j++)cout << card[j] << ' ';
      //cout << endl;

      for(int j=0; j<c; j++){
	esc[j] = card[p-1+j];
      }
      for(int j=0; j<p; j++){
	card[p-j-1]=card[p-j-1-c];
      }
      for(int j=0; j<c; j++){
	card[j] = esc[j];
      }

      //cout << "now:";
      //for(int j=0; j<n; j++)cout << card[j] << ' ';
      //cout << endl;
      //cout << "esc:";
      //for(int j=0; j<c; j++)cout << esc[j] << ' ';
      //cout << endl;
    }

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

  return 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[100];
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>
using namespace std;

#define FOR(i, a, n) for(int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

  while(true) {
    int n, r;
    int p, c;
    int temp;
    cin >> n >> r;
    if(n + r == 0) break;

    int a[100];
    REP(i, n) {
      a[i] = i + 1;
    }

    REP(i, r) {
      cin >> p >> c;
      REP(k, c) {
        FOR(j, n - p, n - 1) {
            temp = a[j - k];
            a[j - k] = a[j + 1 - k];
            a[j + 1 - k] = temp;
        }
      }
    }
    cout << a[n - 1] << endl;

  }






}

C++: #include <iostream>

using namespace std;

int main(void) {
  int yama[51], tmp[51];

  int n, r;
  while (cin >> n >> r, (n || r)) {
    // initialization
    for (int i=0; i<n; i++) {
      yama[i] = i + 1;
    }

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

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

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

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

int main(){
  int n,r;
  while(cin >> n >> r, n){
    int npos[100];
    for(int i=0;i<n;i++){
      npos[i] = n-i;
    }
    for(int i=0;i<r;i++){
      int a,b;
      cin >> a >> b;
      int tmp[b];
      for(int j=0;j<b;j++){
	tmp[j] = npos[j+a-1];
      }
      for(int j=a+b-1;j>=b-1;j--){
	npos[j] = npos[j-b];
      }
      for(int j=0;j<b;j++){
	npos[j] = tmp[j];
      }
    }
    cout << npos[0] << endl;
  }
}

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

int main(void){
  while(1){
    int n, r;
    cin >> n;
    cin >> r;
    if(n == 0 && r == 0){return 0;}

    int f[n];
    for(int i = 0 ; i < n ; i++){
      f[i] = n - i;
    }

    int p[r];
    int c[r];
    for(int i = 0 ; i < r ; i++){cin >> p[i]; cin >> c[i];}


    for(int i = 0 ; i < r ; i++){
      int tempu[p[i]-1];
      int tempd[c[i]];
      for(int j = 0 ; j < p[i]-1 ; j++){
        tempu[j] = f[j];
      }
      for(int j = 0 ; j < c[i] ; j++){
        tempd[j] = f[j + p[i] -1];
      }
      for(int j = 0 ; j < c[i] ; j++){
        f[j] = tempd[j];
      }
      for(int j = 0 ; j < p[i]-1 ; j++){
        f[j+c[i]] = tempu[j];
      }
    }

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

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
using namespace std;

int n,r,p,c;
int before[50],after[50],tmp[50];

void init(){
	for(int i=0;i<50;i++)
		after[i]=tmp[i]=0;
}

bool input(){	
	int i;
	cin>>n;
	cin>>r;
	if((n==0) && (r==0))
		return false;
	for(i=0;i<n;i++)
		before[i]=n-i;	
	return true;
}

void Shuffle(int b[], int a[], int t[]){
	int j;
	for(j=0;j<c;j++){
			a[j]=b[p-1+j];
			t[j]=b[p-1+j];
		}
		for(j=0;j<p;j++){
			a[c+j]=b[j];
			t[c+j]=b[j];
		}
		for(j=0;j<n;j++)
			b[j]=t[j];
}


int solve(){
	for(int i=0;i<r;i++){
		cin>>p>>c;
		Shuffle(before,after,tmp);
	}
	return after[0];
}


int main(){
  while(init(),input()){
	cout<<solve()<<endl;
  }
  return 0;
}

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

class Hanafuda
{
  public:
    Hanafuda(int size);
    ~Hanafuda();
    void Shuffle(int p, int c);
    int Top();

  private:
    int* m_hanafuda;
    int m_size;
};

Hanafuda::Hanafuda(int size)
{
  m_size = size;
  m_hanafuda = new int[m_size];
  for (int i = 0; i < m_size; ++i)
  {
    m_hanafuda[i] = m_size - i;
  }
}

Hanafuda::~Hanafuda()
{
  delete[] m_hanafuda;
}

void Hanafuda::Shuffle(int p, int c)
{
  int* buf_p = new int[p-1];
  int* buf_c = new int[c];

  copy(m_hanafuda, m_hanafuda + p  - 1, buf_p);
  copy(m_hanafuda + p - 1, m_hanafuda + p - 1 + c, buf_c);
  
  copy(buf_c, buf_c + c, m_hanafuda);
  copy(buf_p, buf_p + p - 1, m_hanafuda + c);
}

inline int Hanafuda::Top()
{
  return m_hanafuda[0];
}

int main(void)
{
  while (true)
  {
    int n, r;
    cin >> n >> r;
    if ( n == 0 and r == 0 ) break;

    Hanafuda hanafuda(n);

    int p, c;
    for (int i = 0; i < r; ++i)
    {
      cin >> p >> c;
      hanafuda.Shuffle(p, c);
    }

    cout << hanafuda.Top() << endl;
  }
  return 0;
}