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;

int n, r;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		cin >> n >> r;
		if(n == 0 && r == 0) return 0;
		int a[n] = {};
		for(int i=0; i<n; ++i)
			a[i] = n-i;
//		for(int i=0; i<n; ++i)
//			cout << a[i] << (i==n-1?"\n":" ");
		for(int i=0; i<r; ++i){
			int p, c;
			cin >> p >> c;
			int b[c] = {};
			for(int i=0; i<c; ++i)
				b[i] = a[p+i-1];
			for(int i=p-2; i>=0; --i)
				a[c+i] = a[i];
//			for(int i=0; i<n; ++i)
//				cout << a[i] << (i==n-1?"\n":" ");
			for(int i=0; i<c; ++i)
				a[i] = b[i];
//			for(int i=0; i<n; ++i)
//				cout << a[i] << (i==n-1?"\n":" ");
		}
		cout << a[0] << "\n";
	}
}

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

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

C++: #include <stdio.h>

int main(void)	{
	
	int n, r, p, c, res;
	int yama[50];
	int temphigh[50];
	int templow[50];
	
	while (true)	{
		
		scanf("%d %d", &n, &r);
		
		if (n == 0)	{
			break;
		}
		
		// 山札の初期化
		for (int i = 0; i <= 49; i++)	{
			yama[i] = 50 - i;
			//printf("yama[%d] = %d\n", i, yama[i]);
		}
		
		for (int i = 1; i <= r; i++)	{

			scanf("%d %d", &p, &c);
			
			// p枚の札をtemphighにうつしとる
			for (int j = 0; j <= p-2; j++)	{
				temphigh[j] = yama[j];
			}
			
			// c枚の札をtemplowにうつしとる
			for (int j = 0; j <= c-1; j++)	{
				templow[j] = yama[j + (p-1)];
			}
			
			// c枚分山札を下にずらす
			for (int j = 0; j <= p-2; j++)	{
				yama[j + c] = temphigh[j];
			}
			
			////////////////////////////////////
			//printf("ずらす---------------\n");
			//for (int k = 0; k <= n-1; k++)	{
			//	printf("yama[%d] = %d\n", k, yama[k]);
			//}
			
			// templowを山札の上部にうつしとる
			for (int j = 0; j <= c-1; j++)	{
				yama[j] = templow[j];
			}
			
			//
			//printf("上部に戻す-------------\n");
			//for (int k = 0; k <= n-1; k++)	{
			//	printf("yama[%d] = %d\n", k, yama[k]);
			//}
			
		}
		
		res = yama[0] - (50 - n);
		
		printf("%d\n", res);
	}
	
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int n, r; cin >> n >> r;
		if (n == 0) break;
		vector<int> a(n);
		for (int i = 0; i < n; i++) a[i] = n - i;
		while (r--) {
			int p, c; cin >> p >> c;
			vector<int> _a = a;
			for (int i = 0; i < p + c - 1; i++)
				_a[i] = a[i < c ? p + i - 1 : i - c];
			a = _a;
		}
		cout << a[0] << endl;
	}
}

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

int main(){

  int n, r, p, c, i, k;

  while(cin >> n >> r, n+r){
    int a[n+1];
    int down[n+1];
    for(i = 1; i <= n; i++){
      a[i] = n - i + 1;
      //cout << a[i] << endl;
    }
    for(k = 0; k < r; k++){
      cin >> p >> c;
      int j = 0;
      for(i = 1; i < p; i++){
        down[i] = a[i];
      }
      for(i = 1; i <= c; i++){
        a[i] = a[p - 1 + i];
      }
      for(i = 1; i < p; i++){
        a[c+i] = down[i];
      }
    }
    cout << a[1] << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
	//ifstream fin("input.txt");

	//if (!fin)return -1;

	list<int> stock;

	while (true) {

		int number = 0;
		int shuffleCount = 0;
		int top = 0;

		cin >> number >> shuffleCount;
		if (number == 0 && shuffleCount == 0)break;

		//????????????????´??????????(?±±?????????)
		for (int i = 1; i <= number; i++) {
			stock.push_front(i);
		}

//		ShowList(stock);
		list<int>::iterator begin;
			list<int>::iterator end;

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

			if (number == c)continue;
			begin = stock.begin();
			advance(begin, p - 1);
//			cout << "\t" << *begin << endl;

			end = begin;
			advance(end, c);
//			cout << "\t" << *end << endl;

			stock.splice(stock.begin(), stock, begin, end);

		}
//		ShowList(stock);
		cout << stock.front() << endl;

		stock.clear();
	}
	return 0;
}

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

int main(){
	while(1){
		int n,r;
		cin>>n>>r;
		if(n==0&&r==0)break;
		vector<int> a(n);
		for(int i = 0;i<n;i++){
			a[i]=n-i-1;
		}
		for(int i = 0;i<r;i++){
			int p,c;
			cin>>p>>c;
			for(int j=0;j<n;j++){
				if(a[j]<p-1){
					a[j]+=c;
				}else if(a[j]<p+c){
					a[j]-=(p-1);
				}
			}
		}
		//cout<<"a"<<endl;
		for(int i=0;i<n;i++){
			if(a[i]==0)cout<<i+1<<endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
 
#define rep(i, n) for(int i=0; i<(n); ++i)

int main(void){
    int n, r;
    while(cin >> n >> r && n && r) {
        vector<int> card(n);
        vector<int> tmp(n);
        rep(i, n) card[i] = n-i;
        rep(i, r) {
            int p, c;
            cin >> p >> c;
            rep(j, n) tmp[j] = card[j];
            rep(j, c) tmp[j] = card[p-1+j];
            rep(j, p-1) tmp[c+j] = card[j];
            rep(j, n) card[j] = tmp[j];
        }
        cout << card[0] << endl;
    }
}

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

using namespace std;

int main( void ){
	vector< int > result;
	deque< int > card;
	while( true ){
		int n, r;
		cin >> n >> r;
		if( n == 0 && r == 0 )
			break;
		for( int i = 1; i < n + 1; i++ ){
			card.push_front( i );
		}
		for( int i = 0; i < r; i++ ){
			int p, c;
			cin >> p >> c;
			for( auto itr = card.begin(); itr != card.end(); ++itr ){
				if( ( *itr ) =< p ){
					int temp = ( *itr );
					card.erase( itr );
					card.push_front( temp );
				}
			}
		}

		result.push_back( card.front() );
			
	}

	for( auto itr = result.begin(); itr != result.end(); ++itr ){
		cout << ( *itr ) << endl;
	}

	return 0;
}

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

int n, r, p, c;
int h[51];

int main() {
  while(cin>>n>>r,n|r) {
    for(int i=0;i<n;++i) {
      h[i+1] = i+1;
    }
    for(int i=0;i<r;++i) {
      cin>>p>>c;
      rotate(h+1, h+p+1, h+p+c+1);
    }
    cout << h[1] <<endl;
  }
  return 0;
}