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 <stdio.h>

int main(void)
{
	int deck[51] = {0};
	int n=0;
	int r=0;
	int p[51] = {0};
	int c[51] = {0};
	int downs[51] = {0};
	int ups[51] = {0};
	int i,j;
	int endflag = 0;
	int out[1000]={0};
	int outc=0;

	while(1)
	{
		
		scanf("%d",&n);
		scanf("%d",&r);

		if(n == 0 && r == 0)
		{
			for( i = 0; i < outc ; i++)
				printf("%d\n",out[i]);

			return 0;
		}

		
		for( i = 0; i < r ; i++)
		{
			scanf("%d",&p[i]);
			scanf("%d",&c[i]);
		}



		for(i = 1 ; i < n + 1 ; i++)
		{
			deck[i-1] = n + 1 - i;
		}


		for( j = 0 ; j < r ; j++)
		{
			for(i = 0 ; i < p[j] - 1 ; i++)
			{
				downs[i] = deck[i];
			}
			for(i = 0 ; i < c[j]  ; i++)
			{
				ups[i] = deck[i+p[j]-1];
			}

			for(i = 0 ; i < c[j] ; i++)
			{
				deck[i] = ups[i];
			}
			for(i = 0 ; i < p[j] - 1 ; i++)
			{
				deck[i+c[j]] = downs[i];
			}

			for(i = 0; i < p[j] + c[j] - 1 ; i++)
			{
				ups[i] = 0;
				downs[i] = 0;
			}

		}

		out[outc] = deck[0];
		outc++;

		for(i = 0; i < 50; i++)
			{
				deck[i] = 0;
				p[i] = 0;
				c[i] = 0;
			}


	}


}

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

int main(){
  int n,r,p,c;

  while(cin >> n >> r , n + r){
    vector<int> cards;

    for(int i = n ; i >= 1 ; i--){
      cards.push_back(i);
    }

    while(r--){
      cin >> p >> c;
      vector<int> tmp;
      for(int i = p-1 ; i < p+c-1 ; i++){
	tmp.push_back(cards[i]);
      }
   
      for(int i = 0 ; i < cards.size() ; i++){
	tmp.push_back(cards[i]);
      }
      for(int i = 0 ; i < n ; i++){
	cards[i] = tmp[i];
      }

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

  return 0;
}

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

int main(){
    int n,r,p,c;
    while(cin >> n >> r, n&&r){
        vector<int> cards;
        for(int i = 0; i < n; i++){
            cards[i] = n - 1;
        }
        while(r--){
            cin >> p >> c;
            vector<int> cpCards = cards;
            int pos = 0;
            for(int i = p - 1; i < p - 1 + c; i++){
                cards[pos] = cpCards[i];
                pos++;
            }
            for(int i = 0; i < p - 1; i++){
                cards[pos] = cpCards[i];
                pos++;
            }
        }
        cout << cards.front() << endl;
    } 
}

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

int main(void)
{

	int n,r;
	int p,c;
	int i1,i2;

	
	cin << n << r;

	

	vector<int> fuda(n),temp(n);

	/* syokika */
	for(i1=0;i1<n;i1++){
		fuda[i1] = i1+1;
//		cout << fuda[i1] << " ";

	}

	/* copy */
	for(i1=0;i1<p-1;i1++){
		temp[i1] = fuda[i1];
	}


	/* shuffle */
	for(i1=0;i1<c;i1++){
		fuda[i1] = fuda[p-1+i1];
	}
	for(i1=c;i1<p-1+c;i1++){
		fuda[i1] = temp[i1-c];
	}


	for(i1=0;i1<n;i1++){
		cout << fuda[i1] << " ";
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;

const int INF = 1 << 29;
typedef pair<int, int> P;

int n, r;

int main(void)
{
	while(cin >> n >> r && n)
	{
		vector<int> hudas(n);
		for (int i = 0; i < n; i++)
			hudas[i] = n - i;
		for (int i = 0; i < r; i++)
		{
			int p, c;
			cin >> p >> c, p--;

			vector<int> tmp;
			for (int j = 0; j < c; j++)
			{
				tmp.push_back(hudas[p + j]);
			}
			for (int j = 0; j < n; j++)
			{
				if(j < p || j >= p + c)
					tmp.push_back(hudas[j]);
			}
			hudas = tmp;
		}

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

C++: #include <iostream>
#include <cassert>
#include <deque>
#define REP(i,l,n) for(int i=l;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define MAX 50
using namespace std;
int ans;
int n,r,c,p;
deque<int> deck;
int main() {
  while(1){
    cin >> n >> r;
    if(n==0&&r==0) return 0;
    deck.clear();
    rep(i,n) deck.push_front(i+1);
    rep(i,r){
      cin >> p >> c;
      rep(j,c){
        deck.push_front(deck[p-1+c-1]);
        deck.erase(deck.begin()+p-1+c);
      }
    }
    ans = deck[0];
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

int main() 
{
	int n,m;
	while(cin >> n >> m && n>0 && m>0)
	{
		int a[50]={0};
		for(int i=0;i<n;i++){	a[i]=n-i;	}
		
		for(int i=0;i<m;i++)
		{
			int x,y;
			cin >> x >> y;
			rotate(a,a+x-1,a+x+y-1);
		}
		cout << a[0] << endl;
	}
	return 0 ;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TEMP_T T    cums(T& v){ T r(v.size()); partial_sum(v.begin(), v.end(), r.begin()); return r; }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }
TEMP_T T    acum(vector<T>& v, T b=0){ return accumulate(v.begin(), v.end(), b); }
TEMP_T vector<T> inpt(int n){ vector<T> v(n); for (int i=0; i<n; i++) cin >> v[i]; return v; }

static inline int in(){ int x; scanf("%d", &x); return x; }

int main()
{
  int n, r;
  while (n = in(), r = in(), n || r){
    deque<int> d(n);
    for (int i = 0; i < n; i++) d[i] = i;
    revs(d);
    for (int i = 0; i < r; i++){
      int p, c;
      p = in() - 1;
      c = in();
      deque<int> buf;
      for (int i = 0; i < c; i++){
        buf.push_front(d[p + i]);
      }
      d.erase(d.begin() + p, d.begin() + p + c);
      for (int i = 0; i < c; i++){
        d.push_front(buf[i]);
      }
    }
    cout << d[0] + 1 << endl;
  }
  return (0);
}

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

#define R input[0][1]

using namespace std;

int input() {
	int input[51][2];
	cin >> input[0][0] >> input[0][1];								//まずnとr
	if (input[0][0] == 0 && input[0][1] == 0) {
		return 0;
	}
	for (char pos = 1; pos <= input[0][1]; pos++) {					//r回のシャッフルの仕方を入力
		cin >> input[pos][0] >> input[pos][1];
	}																//ここまで入力

	/*シャッフルもどし*/
	int whtop = 1;													//最後一番上にいるカードは、今何番目にいる？
	if (R==0)return input[0][0];									//一回もシャッフルしないならコレ

	whtop = input[input[0][1]][0];									//一回目のもどしだけ別枠
	R--;
	while (input[0][1] != 0) {	
		if (whtop <= input[R][1]) whtop = whtop + input[R][0] - 1;
		else if ((input[R][0] + input[R][1] - 1) < whtop) whtop = whtop;
		else whtop = whtop - input[R][1];
		R--;
	}
	return input[0][0] - whtop + 1;

}


int main()
{
	while (1) {
		int check;
		check = input();
		if (check == 0)break;
		else {
			cout << check << endl;
		}
	}
}