Go: package main

import "fmt"

func main() {
	var n, r int
	fmt.Scan(&n, &r)
	for n != 0 || r != 0 {
		arr := make([]int, n)
		for i := range arr {
			arr[i] = len(arr) - i
		}

		for i := 0; i < r; i++ {
			var p, c int
			fmt.Scan(&p, &c)
			mid, top, last := arr[:p-1], arr[p-1:p-1+c], arr[p-1+c:]
			arr = append(append(append([]int{}, top...), mid...), last...)
		}
		fmt.Println(arr[0])
		fmt.Scan(&n, &r)
	}
}

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;
}

C++: #include<iostream>
#define rep(n) for(int j = 1; j < n + 1; j++)
using namespace std;
int main() {
	int n, r;
	while (cin >> n >> r){
		if (n == 0 && r == 0)return 0;
		int deck[60];
		for (int i = 1; i < n + 1; i++){
			deck[i] = i;
		}
		for (size_t i = 0; i < r; i++){
			int p, c, d[60]; cin >> p >> c;
			rep(p - 1) d[j] = deck[j];
			rep(c) deck[j] = deck[p + j];
			rep(p - 1) deck[c + j + 1] = d[j];
		}
		cout << deck[1] << endl;
	}
}