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>

using namespace std;

int N, R, p, c, i, j;
int A[N] = {};

int main()
{
   while ( cin >> N >> R && N >0 )
   {
      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 <string>
#include <vector>

using namespace std;

int main(){
	int n, r;
	
	while(cin >> n >> r, n | r){
		vector<int> p, c;
		int tempp, tempc;
		vector< vector<int> > deck;
		
		deck.resize(r + 1);
		for(int i = 0; i <= r; i++){
			deck[i].resize(n);
		}
		
		for(int i = 0; i < n; i++){
			deck[0][i] = n - i;
		}
		
		for(int i = 0; i < r; i++){
			cin >> tempp >> tempc;
			p.push_back(tempp);
			c.push_back(tempc);
		}
		
		for(int i = 1; i <= r; i++){
			int count = 0;
			for(int j = p[i - 1] - 1; j < p[i - 1] + c[i - 1] - 1; j++){
				deck[i][count] = deck[i - 1][j];
				count++;
			}
			for(int k = 0; k < p[i - 1] - 1; k++){
				deck[i][count] = deck[i - 1][k];
				count++;
			}
			for(int l = p[i - 1] + c[i - 1] - 1; l < n; l++){
				deck[i][count] = deck[i - 1][l];
				count++;
			}
		}
		
		cout << deck[r][0] << endl;
	}
	
	return 0;
}

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

int main(){
  while(1){
    int n,r;
    std::cin>>n>>r;
    if(n==0&&r==0) break;
    std::vector<int> hanafuda(n),tmp(n);
    for(int i=0;i<n;++i) hanafuda[i]=n-i;

    for(int i=0;i<r;++i){
      for(int j=0;j<n;++j)
        tmp[j]=hanafuda[j];
      int p,c;
      std::cin>>p>>c;
      for(int j=0;j<c;++j) hanafuda[j] = tmp[p-1+j];
      for(int j=0;j<p-1;++j) hanafuda[c+j] = tmp[j];
    }
    std::cout<<hanafuda[0]<<std::endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
    int n,r,p,c;
    while(true){
        cin>>n>>r;
        if(n==0&&r==0){
            break;    
        }else{
            int A[n];
            for(int i=0;i<n;i++){
                A[i]=n-i;   
            }
            for(int j=0;j<r;j++){
                cin>>p>>c;
                int B[p-1];
                for(int i=0;i<p-1;i++){
                    B[i] = A[i];  
                }
                for(int i=0;i<c;i++){
                    A[i]=A[p-1+i];   
                }
                for(int i=0;i<p-1;i++){
                    A[c+i]=B[i];   
                }
            }
            cout<<A[0]<<endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <list>
#define rep(i,n) for(int i = 0; i < n;i++)

using namespace std;
int main(int argc, const char * argv[]){
    int n,r;
    int p,c;
    int A[100];
    while(cin >> n >> r && n){
        for(int i=0;i < n;i++){
            A[i]=n-i;
        }
        for(int i = 0;i < r;i++){
            cin >> p >> c;
            rotate(A,A+p-1,A+p+c-1);

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

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,r,p,c;
  while(cin>>n>>r&&n){
    vector<int> A(n);
    for(int i=0;i<n;i++) A[i]=n-i;
    for(int i=0;i<r;i++){
      cin>>p>>c;
      rotate(A.begin(),A.begin()+p-1,A.begin()+p+c-1);
    }
    cout<<A[0]<<endl;
  }
}

C++: #include <stdio.h>

int main(void){
  int n, r, p, c, i;
  while(1){
    scanf("%d%d", &n, &r);
    if (n==0 && r==0){
      break;
    }
    int card[n], temp[n];
    for(i=0;i<n;i++){
      card[i] = n-i;
    }
    for(i=0;i<r;i++){
      scanf("%d%d", &p, &c);
      //カットの処理
      for(i=p-1;i<p+c-1;i++){
        temp[i-p+1] = card[i];
      }
      for(i=0;i<p-1;i++){
        card[p+c-2-i] = card[p-2-i];
      }
      for(i=0;i<c;i++){
        card[i] = temp[i];
      }
    }
    printf("%d", card[0]);
  }
  return 0;
}

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

queue<int> shuffle(queue<int>,int,int);

int main(int argc,char* argv[]){
  int n,r,p,c,val;

  while(true){
	cin >> n >> r;
	if(n == 0 || r == 0)
	  break;

	queue<int>que;
	for(int i = 1;i <= n;i++)
	  que.push(i);
	
	for(int i = 0;i < r;i++){
	  cin >> p >> c;
	  que = shuffle(que,p,c);
	}

	while(!que.empty()){
	  val = que.front();que.pop();
	}
	cout << val << endl;
  }

  return 0;
}

queue<int> shuffle(queue<int> que,int p,int c){
  queue<int> tmp;
  int n = que.size();
  for(int i = 1;i <= n;i++){
	if(i <= (n-(c+p-1)) || i > n-(p-1)){
	  que.push(que.front());
	  que.pop();
	}
	else{
	  tmp.push(que.front());
	  que.pop();
	}
  }
  while(!tmp.empty()){
	que.push(tmp.front());
	tmp.pop();
  }
  return que;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <sstream>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;

const int MAX_N = 50;
int n, r, p, c;

int cards_a[MAX_N], cards_b[MAX_N];

int main() {
    while(cin >> n, cin >> r, n != 0 && r != 0) {
        for(int i = 0; i < n; i++) cards_a[i] = n - i;

        for(int i = 0; i < r; i++) {
            cin >> p >> c;
            for(int j = 0; j < p - 1; j++) {
                cards_b[j + c] = cards_a[j];
            }
            for(int j = 0; j < c; j++) {
                cards_b[j] = cards_a[j + p - 1];
            }
            for(int j = 0; j < p + c - 1; j++) {
                cards_a[j] = cards_b[j];
            }
        }
        cout << cards_a[0] << endl;
    }

    return 0;
}

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

int main(void) {
    int n, r;
    while (cin >> n >> r, n+r) {
        vector<int> h(n);
        for (int i = 0; i < n; i++) {
            h[i] = n-i;
        }

        int p, c;
        for (int i = 0; i < r; i++) {
            cin >> p >> c;
            vector<int> tmp;
            for (int j = 0; j < c; j++) {
                tmp.push_back(h[p-1+j]);
            }
            for (int j = 0; j < p-1; j++) {
                tmp.push_back(h[j]);
            }
            for (int j = 0; j < tmp.size(); j++) {
                h[j] = tmp[j];
            }

            // cout << "#: ";
            // for (int j = 0; j < n; j++) {
            //     cout << " " << h[j];
            // }
            // cout << endl;
        }

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

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

int main()
{
	
		int n, r, c, p, i, j, k, yama[50], hikae[50];
		while (1)
		{
			cin >> n >> r;
			if (n == 0)
				break;
			for (i = 0; i < n; i++)
			{
				yama[i] = i + 1;
			}
			for (i = 0; i < r; i++)
			{
				cin >> p >> c;
				for (j = 0; j < n - p - c + 1; j++)
					hikae[j] = yama[j];
				for (k = 0; k < c; k++)
					hikae[n - k - 1] = yama[n - p - k];
				for (k = 0; k < p - 1; k++)
					hikae[n - c - k - 1] = yama[n - k - 1];
				for (j = 0; j < n; j++)
					yama[j] = hikae[j];
			}
			cout << yama[n - 1];
		}
	return 0;
}