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

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

    vector<int> hana(n);
    for(int i=0; i<n; i++)
      hana[i] = n-i;

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

      vector<int> temp(p-1);
      for(int j=0; j<p-1; j++)
	temp[j] = hana[j];
      for(int j=0; j<c; j++)
	hana[j] = hana[j+p-1];
      for(int j=0; j<p-1; j++)
	hana[j+c] = temp[j];
    }

    cout << hana[0] << endl;
  }
  
  return 0;
}

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

using namespace std;

vector<int> Shuffle(int, int, vector<int>);

int main(){
  int i, n, r, p, c;
  vector<int> data;

  while(1){
    cin >> n >> r;
    if(n == 0 && r == 0) break;

    for(i=n; i>0; --i)
      data.push_back(i);

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

    cout << data[0] << endl;
    data.clear();
  }

  return 0;
}

vector<int> Shuffle(int p, int c, vector<int> x){
  vector<int> y;

  copy(x.begin()+p-1, x.begin()+p+c-1, back_inserter(y));
  copy(x.begin(), x.begin()+p-1, back_inserter(y));
  copy(x.begin()+p+c-1, x.end(), back_inserter(y));

  return y;
}

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

int main() {
  int n, r;
  while (cin >> n >> r, n) {
    auto v = vector<int>(n);
    iota(begin(v), end(v), 1);
    reverse(begin(v), end(v));

    auto tmp = v;
    for (int i = 0; i < r; ++i) {
      int p, c; cin >> p >> c;
      for (int i = 0; i < c; ++i) tmp[i] = v[i + p - 1];
      for (int i = 0; i < p - 1; ++i) tmp[i + c] = v[i];
      v = tmp;
    }
    cout << v[0] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)

typedef long long ll;


int main(void) {
    int n,r;
    while (cin>>n>>r && n){
        vector<int> a(n);
        REP(i,n){
            a[i] = i+1;
        }
        while(r--){
            int p,c;
            cin >> p >> c;
            REP(i,c){
                int k=a[n-p-c+1];
                a.erase(a.begin()+n-p-c+1);
                a.push_back(k);
            }
        }
        cout << a[n-1] << endl;
    }
    
    return 0;
}

C++: #include<iostream>
#include<cstdio>

using namespace std;

int n,r;

int c1[1001],c2[1001];

int main(void){
	while(1){
		scanf("%d%d",&n,&r);
		if(n==0)break;
		for(int i=0;i<n;i++)c1[i]=c2[i]=n-i;
		for(int i=0;i<r;i++){
			int p,c;
			scanf("%d%d",&p,&c);
			for(int j=0;j<c;j++)c2[j]=c1[j+p-1];
			for(int j=c;j<c+p-1;j++)c2[j]=c1[j-c];
			for(int j=c+p;j<n;j++)c2[j]=c1[j];
			for(int j=0;j<n;j++){
				c1[j]=c2[j];
				//printf("%d\n",c1[j]);
			}
		}
		printf("%d\n",c1[0]);
	}
	return 0;
}

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

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

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;

int main(void) {
	int N, R;
	while (cin >> N >> R, N) {
		if (N == 1){
			cout << 1 << endl;
			continue;
		}
		
		stack<int> yama;
		for (int i = 1; i <= N; i++) {
			yama.push(i);
		}

		for (int i = 0; i < R; i++) {
			stack<int> p;
			stack<int> c;
			int begin, size;
			cin >> begin >> size;

			for (int j = 0; j < begin - 1; j++) {
				p.push( yama.top() );
				yama.pop();
			}
			for (int j = 0; j < size; j++) {
				c.push ( yama.top() );
				yama.pop();
			}

			while (!p.empty()) {
				yama.push( p.top() );
				p.pop();
			}
			while (!c.empty()) {
				yama.push( c.top() );
				c.pop();
			}
		}

		cout << yama.top() << endl;
	}

	return 0;
}

C++: #include <cstdio>

int main()
{
    int deck[50] = {}, tam[50] = {}, num, times, p, c;

    while (1)
    {
        scanf("%d %d", &num, &times);
        if (num == 0 && times == 0)
        {
            break;
        }
        for (int i = 0; i < num; i++)
        {
            deck[i] = num - i;
        }

        for (int i = 0; i < times; i++)
        {
            scanf("%d %d", &p, &c);
            for (int j = 0; j < p - 1; j++)
            {
                tam[j] = deck[j];
            }
            for (int j = 0; j < c; j++)
            {
                deck[j] = deck[j + p - 1];
            }
            for (int j = 0; j < p - 1; j++)
            {
                deck[c + j] = tam[j];
            }
        }
        printf("%d\n", deck[0]);
    }
}

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

int main(){

  while(1){
    int card,x;
    cin >> card >> x;
    if(card==0 && x == 0) break;
    int p[100];
    for(int i = 1; i <= card;i++){
      p[card-i+1] = i;
    } 
    for(int i = 1;i <= card;i++){
      //   cout << p[i] << endl;
    }
    for(int i = 0; i < x;i++){
      int a,b;
      cin >> a >> b;
      int tmp[200]={};
      for(int j = 1 ; j < a ; j++){
	tmp[j]= p[j];
      } 
      for(int j = 1; j <= b; j++){
	p[j] = p[a+j-1];
      }
      for(int j = b+1; j <= a+b-1; j++){
	p[j] = tmp[j-b];
      }
    }
    for(int i = 1;i <= card;i++){
      //  cout << p[i] << endl;
    }
    cout << p[1] << endl;

  }
  return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

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

    int n,r;
    while(cin>>n>>r,n&&r){
        vector<int> old_cards(n),new_cards(n);
        for(int i=0;i<n;i++) old_cards[i]=n-i;
        for(int j=0;j<r;j++){
            int p,c;cin>>p>>c;
            for(int i=0;i<c;i++) new_cards[i]=old_cards[p-1+i];
            for(int i=c;i<p-1+c;i++) new_cards[i]=old_cards[i-c];
            for(int i=p-1+c;i<n;i++) new_cards[i]=old_cards[i];

            for(int i=0;i<n;i++) old_cards[i]=new_cards[i];
        }
        cout<<old_cards[0]<<endl;
    }
}