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

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

//?±±?????????????????¢??°???????±±???????±±????????°n???p?????????????????????c???                       
void shuffle(vector<int> &yama, int n, int p, int c);


int main(){
  int n, r;
  int p, c;
  vector<int> yama, v;

  cin >> n;
  cin >> r;

  while(n != 0 && r != 0){
    //?±±??????????????????                                                            
    for(int i = 0, j = n; i < n; i++, j--){
      yama.push_back(j);
    }
    //?????£?????????                                                                
    for (int i = 0; i < r; i++){
      cin >> p;
      cin >> c;
      shuffle(&yama, n, p, c);
    }
    //???????????????????¨????                                                          
    v.push_back(yama.front());

    cin >> n;
    cin >> r;
  }
  for(int i = 0; i < v.size(); i++){
    cout << v[i];
  }
  cout << endl;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <tuple>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
int main(void)
{
  for(;;){
    int n,r;
    deque<int> deck;
    cin >> n >> r;
    REP(i,n) deck.push_front(i+1);
    if(!n&&!r) return 0;
    REP(i,r){
      int p,c;
      cin >> p >> c;
      REP(j,c){
	deck.push_front(deck[p+c-2]);
	deck.erase(deck.begin()+p+c-1);
      }
    }
    cout << deck.front() << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
  int n,r;
  while(cin>>n>>r,n!=0||r!=0){
  int A[n];
  rep(i,n){
    A[i]=n-i;
  }
  rep(i,r){
    int p,c;
    cin>>p>>c;
    vector<long long> v(c);
    for(int j=p-1;j<p+c-1;j++){
      v[j-(p-1)]=A[j];
    }
    for(int j=p-2;j>=0;j--){
      A[j+c]=A[j];
    }
    for(int j=0;j<c;j++){
      A[j]=v[j];
    }
  }
  cout<<A[0]<<endl;
  }
 return 0;
}