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 <bits/stdc++.h>

using namespace std;

int n[10000]={},r[10000]={};
int p[10000][50] = {};
int c[10000][50] = {};
int i=0;

int d[50]={};
int e[50] = {}; //今の状態
int e2[50] = {};

int main(){
    while(1){
        scanf("%d %d",&n[i],&r[i]);
        if(n[i]== 0 && r[i]== 0){
            break;
        }
        for(int j=0;j<r[i];j++){
            scanf("%d %d",&p[i][j],&c[i][j]);
        }
        i++;
    }
    int times = i;
    for(i=0;i<times;i++){
        //初期化
        int s=0;
        for(int k = n[i]; k>0;k--){
            e[s] = k;
            s++;
        }
        for(int j=0;j<r[i];j++){
            s=0;
            for(int t=p[i][j]-1;t<p[i][j]+c[i][j]-1;t++){
                d[s] = e[t];
                s++;
            }
            for(int t = 0;t < n[i];t++){
                e2[t] = e[t];
            }
            for(int t = 0;t<c[i][j];t++){
                e[t] = d[t];
            }
            for(int t=0;t<n[i]-c[i][j];t++){
                e[t+c[i][j]] = e2[t];
            }

        }
        
        cout << e[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> resultCards = cards;
            int pos = 0;
            for(int i = p - 1; i < p - 1 + c; i++){
                resultCards[pos] = cards[i];
                pos++;
            }
            for(int i = 0; i < p - 1; i++){
                resultCards[pos] = cards[i];
                pos++;
            }
        }
    }
}

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

using namespace std;

int top_search(int,int,int,int *);
int main(){
	int n,r,c,p;
	while(1){
		cin>>n>>r;
		if(n==0&&r==0)
			break;
		int *hanahuda=new int[n+1];

		for (int i = n-1; i>=0 ; i--){
			hanahuda[i]=n-i;
		}
		int top;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			top=top_search(n,p,c,hanahuda);
		}
		cout << top << endl;
		delete[] hanahuda;
	}
	
	return 0;
}
int top_search(int n,int p,int c,int *hanahuda){
	int cnt=0;
	for(int k=p-1;k<p+c-1;k++){

		int nokori=hanahuda[k];

		for(int l=p-2;l>=0;l--){
			hanahuda[l+1]=hanahuda[l];
		}

		hanahuda[cnt]=nokori;
		cnt++;
	}
	return *hanahuda;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int d[55];

void init(int n){
  for(int i=0;i<51;i++){
    d[i]=n-i;
  }
}

int main(){
  int n,r;

  while(true){
    cin>>n>>r;
    if(n==0&&r==0)break;
    init(n);
    for(int i=0;i<r;i++){    
      int p,c;
      cin>>p>>c;

      //????????????p~p+c?????£??\
      int cnt=0;
      int tmp[55];
      for(int j=p-1;j<p-1+c;j++){
	tmp[cnt]=d[j];
	cnt++;
      }

      //1~p-1?????§???c?????????????????¨???
      for(int j=p-1;j>=0;j--){
	d[j+c]=d[j];
      }
      
      //p~p+c?????§??????????????£?????????
      for(int j=0;j<c;j++){
	d[j]=tmp[j];
      }
      if(debug)for(int j=0;j<n;j++)cout<<d[j]<<" ";
      if(debug)cout<<endl;
    }
    cout<<d[0]<<endl;
  }
  return 0;
}

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

using namespace std;

vector<int> Deck;

void shuffle(int p, int c) {
  vector<int> tmp = Deck;
  for(int i=0; i<Deck.size(); i++) {
    if(i<c) {
      Deck[i] = tmp[p-1+i];
    }
    else if(c<=i && i<c+p-1) {
      Deck[i] = tmp[i-c];
    }
  }
}

int main() {
  int n, r;

  while(cin>>n>>r && n>0) {
    Deck.clear();
    for(int i=0; i<n; i++) {
      Deck.push_back(n-i);
    }
    for(int i=0; i<r; i++) {
      int p, c;
      cin>>p>>c;
      shuffle(p, c);
    }
    cout<<Deck[0]<<endl;
  }
}

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

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>
#include <vector>

using namespace std;

int main(void) {
  int n, r;
  while (cin >> n >> r && n + r) {
    auto deck = vector<int>(n);
    for (int i = 0; i < n; i++) deck[i] = n-i;
    for (int i = 0; i < r; i++) {
      int p, c; //3 1
      cin >> p >> c;
      auto temp = vector<int>(c);
      for (int j = 0; j < c; j++) temp[j] = deck[p-1+j];
      for (int j = c+p-2; j >= c; j--) deck[j] = deck[j-c];
      for (int j = 0; j < c; j++) deck[j] = temp[j];
    }
    cout << deck[0] << endl;
  }
}

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

int n, r;
int p[64], c[64];

int main() {
  for(;;) {
    scanf("%d %d", &n, &r);
    if( n == 0 and r == 0 ) break;
    for(int i = 0; i < r; ++i) {
      scanf("%d %d", &p[i], &c[i]);
    }
    int res = n;
    for(int i = r - 1; i >= 0; --i) {
      if( n - c[i] < res ) {
        res -= p[i] - 1;
      }
      else if( n - c[i] - (p[i] - 1) < res and res <= n - c[i] ) {
        res += c[i];
      }
    }
    printf("%d\n", res);
  }

  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,r;
    while(cin>>n>>r,n||r){
        vector<int>V[2];
        V[0].resize(n);
        for(int i=0;i<n;i++)V[0][i]=n-i;
        int p,c;
        for(int i=0;i<r;i++){
            cin>>p>>c;
            V[(i+1)&1].clear();
            for(int j=p-1;j<p+c-1;j++)
                V[(i+1)&1].push_back(V[i&1][j]);

            for(int j=0;j<p-1;j++)
                V[(i+1)&1].push_back(V[i&1][j]);
            for(int j=p+c-1;j<n;j++)
                V[(i+1)&1].push_back(V[i&1][j]);
           ///for(int j=0;j<n;j++)cout<<V[(i+1)&1][j]<<" ";
           // cout<<endl;
        }
        cout<<V[r&1][0]<<endl;
    }
}

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

int main(void)
{
    int n,r,p,c;
    int a[200], b[200];
    while(1) {
        cin>>n>>r;
        if(n==0 && r==0) break;
        for(int i=0; i<n; i++)
            a[i] = n - i;

        for(int i=0; i<r; i++) {
            cin >> p >> c;
            for(int j=p-1; j<(p-1)+c; j++) {
                b[j-(p-1)] = a[j];
            }
            for(int j=0; j<n; j++) {
                if(j < p-1 && j > p-1+c)
                    b[j+(p-1)] = a[j];
            }
            for(int j=0; j<n; j++) {
                a[j] = b[j];
            }
            cout << a[0] << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#define N 50
using namespace std;
int main(){
	int n, r, p, c, i, j, card[N+1], memo[N+1];
	while(cin >> n >> r, n){
		for(i = 1; i <= n; i++) card[i] = n - i + 1;
		for(i = 0; i < r; i++){
			cin >> p >> c;
			for(j = 1; j < p; j++) memo[j] = card[j];
			for(j = 1; j <= c; j++) card[j] = card[p + j - 1];
			for(j = 1; j < p; j++) card[c + j] = memo[j];
		}
	cout << card[1] << endl;
	}
	return 0;
}