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 <bits/stdc++.h>
using namespace std;

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

typedef pair<int, int> P;

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
  int N, r;
  while( cin >> N >> r, N | r ){
    vector<P> ope( r );
    REP( i, r ){
      int p, c; cin >> p >> c;
      ope.emplace_back( p, c );
    }

    int t = 1;
    REPR( i, ope.size() - 1 ){
      if( t <= ope[i].second ){
        t += ope[i].first - 1;
      }else{
        if( t <= ope[i].first + ope[i].second - 1 ){
          t -= ope[i].second;
        }
      }
    }
    cout << N - t + 1 << endl;
  }
}

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

int main() {
int N,R,p,c;
while (cin>>N>>R&&N) { 
	int A[100]={};
	for(int i=0;i<N;i++){
		A[i]=i+1;
	}
	reverse(A,A+N);
	for (int i=0; i<R; ++i) {
	cin >> p >> c ;
	rotate(A,A+p,A+p+c);

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

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

using namespace std;

int n,r;
vector<int> ans;
int main(){
	while(1){
		vector<int> m;
		cin >> n >> r;
		if(n + r == 0) break;
		for(int i = 1;i <= n;i++){
			m.push_back(i);
		}
		for(int i = 0; i < r;i++){
			int c,p;
			cin >> p >> c;
			vector<int> nm;
			
			for(int j = 0;j < n;j++){
				if(j<n-p-c+1 || n-p+1<=j){
					nm.push_back(m[j]);
				}
			}
			for(int j = n-p-c+1;j < n-p+1;j++){
				nm.push_back(m[j]);
			}
			
			m = nm;
		}
		ans.push_back(m[n-1]);
	}
	for(int i = 0;i < ans.size();i++){
		cout << ans[i] << endl;
	}
}

C++: #include<stdio.h>

int main(void)
{

  int n[10000]={};
  int r[10000]={};
  int s=0;
  int l=0;
  int x[1000]={};
  int k=0;
  int i=0;
  int j=0;
  int dmm=0;
  
  while(1){
   scanf("%d  %d/n", &n[s], &r[l]);
   
   if(n[s]==0&&r[l]==0)
     break;

   s++;
   l++;
  }
  
  
  s=0;
  l=0;
  
  while(1){
    for(i=0;i<n[s];i++)
      x[i]=n[s]-i;
    int m=l;
    int s2=s;
    for(k=0;k<r[m];k++){
      l++;
      for(i=0;i<r[l];i++){
	dmm=x[n[s+1]-1+i];
	for(j=n[s+1]+i-1;j>i;j--){
	  x[j]=x[j-1];
	}
	x[i]=dmm;
      }
      s++;
    }
    printf("%d\n",x[0]);

    s++;
    l++;

    if(n[s]==0&&r[l]==0)
      break;

  }

    
      
  return 0;
}

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

using namespace std;

int N, R, p, c, i, j;

int main()
{
   while ( cin >> N >> R && N >0 )
   {
      int A[N] = {};
      for ( i = 0; i < N; i++)
         {
            A[i] = N - i;
         }
      for ( j = 0; j<R; j++)
         {
            cin >> p >> c;
            rotate(A,A+(p-1),A+(p+c-1))
         }
      cout << A[0] <<endl;
   }
}

C++: #include <iostream>
#define NUM 60

using namespace std;

int main(){
	int n, r, from[NUM], to[NUM], tmp[NUM]; 
	while(cin>>n>>r, n, r){
		for(int i=0; i<n; i++) from[i] = to[i] = n-i;
		for(int k=0; k<r; k++){
			int p, c, j=0; cin>>p>>c;
			for(int i=0; i<p-1; i++)tmp[i] = from[i];
			for(int i=p-1; i<p+c-1; i++) to[j++] = from[i];
			for(int i=0; i<p-1; i++) to[j++] =tmp[i];
			for(int i=0; i<n; i++) from[i] = to[i];
		}
		cout << from[0] << endl;
	}
	return 0;
}

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

int main(){
  int n, r;
  string cards;
  string left, right, rest;
  stringstream ss;
  int p, c;
  int ans;

  while(cin >> n >> r){
    if((n|r) == 0) break;
    cards = "";
    for(int i=n; i>0; i--){
      ss << i;
      cards = cards + ss.str() + " ";
      if(i<10) cards+= " ";
      ss.str("");
    }

    int pp, cp;
    for(int i=0; i<r; i++){

      cin >> p >> c;
      pp = (p-1)*3;
      cp = c*3;
      left = cards.substr(0, pp);
      right = cards.substr(pp, cp);
      rest = cards.substr(pp+cp);
      cards = right + left + rest;
    }
    string ans="";
    for(int i=0; i<3; i++){
      if(!isspace(cards[i]))ans += cards[i];
    }
    cout << ans << endl;
  
  }
 
 return 0;
}

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

const int STACKMAX = 50;
typedef int elementtype;

typedef struct {
	elementtype elem[STACKMAX];
	int position;
} stack;

void initstack(stack *s) {
	s->position = 0;
}

void push (stack *s, elementtype x) {
	if (s->position >= STACKMAX) {
		cout << "stack overflow" << endl;
		exit(0);
	} else {
		s->elem[s->position] = x;
		s->position++;
	}
}

elementtype pop (stack *s) {
	elementtype element;

	if (s->position < 0) {
		cout << "stack underflow" << endl;
		exit(0);
	} else {
		s->position--;
		return s->elem[s->position];
	}

}

void print (stack *s) {
	for (int i = 0; i < s->position; i++) cout << s->elem[i];
	cout << "\n";
}

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

	int n, r, p, c, i = 1;
	stack *cards1 = (stack *)malloc(sizeof(stack)), *cards2 = (stack *)malloc(sizeof(stack));

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

			initstack(cards1);
			initstack(cards2);

			for (int j = 0; j < p + c - 1; j++) {
				if(j < p - 1) {
					push(cards1, a[j]);
				} else {
					push(cards2, a[j]);
				}
			}

		//	print(cards1);
		//	print(cards2);

			for (int l = p + c - 2; l >= 0; l--) {
				if (cards1->position != 0) {
					a[l] = pop(cards1);
				} else {
					a[l] = pop(cards2);
				}
			}
		}

		cout << a[0] << "\n";
	}

	free(cards1);
	free(cards2);

	return 0;
}

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

using namespace std;

int main(){
	vector<int> cards;
	vector<int> ::iterator cardsIterator;
	vector<int> ::iterator shuffuleIterator;
	int n,r,p,c;

	while(cin >> n >> r, n && r){
		cards.clear(); //初期化
		// カードの山生成
		for (int i = 0; i < n; ++i){
			cards.push_back(i+1);
		}
		// シャッフル
		while(cin >> p >> c, r--){
			cardsIterator = cards.end();
			cardsIterator -= p + (c - 1);
			while(c--){
				cards.push_back(*cardsIterator);
				cards.erase(cardsIterator);
			}
			if (r == 0){
				break;
			}
		}
		// 一番上のカード表示
		cout << cards.back() << endl;
	}
}

C++: #include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1e18 : 1e9;
const int MOD = 1000000007;
const long double EPS = 1e-8;

int main() {
	int n, r;
	while(cin >> n >> r, n) {
		vector <int> yama;
		rep (i, n) yama.push_back(n - i);
		rep (i, r) {
			int p, c;
			cin >> p >> c;
			rep (j, c) {
				int tmp = yama[p + c - 2];
				yama.erase(yama.begin() + p + c - 2);
				yama.insert(yama.begin(), tmp);
			}
		}
		cout << yama.front() << endl;
	}
	return 0;
}