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){

  char inputs[6], tmp[51];
  int inputs_shuffle[51][2], inputs_nr[2], stack[52];
  int loop1, loop2, loop3;

  inputs_nr[0] = '\0';
  inputs_nr[1] = '\0';

  for(loop1 = 0; loop1 < 51; loop1++){
    inputs_shuffle[loop1][0] = '\0';
    inputs_shuffle[loop1][1] = '\0';
  }

  while((inputs_nr[0] == '\0') || (inputs_nr[1] == '\0')){ // get <n r>
    printf("input 'n r'\n");
    scanf("%d %d", &loop1, &loop2);

    inputs_nr[0] = loop1;
    inputs_nr[1] = loop2;
    
    
    if((inputs_nr[0] < 1) || (inputs_nr[0] > 50)){
      printf("<n> must be more than 1 and less than 50.\n");
      inputs_nr[0] = '\0';      // 1 <= n <= 50
      inputs_nr[1] = '\0';
    }

    if((inputs_nr[1] < 1) || (inputs_nr[1] > 50)){
      printf("<r> must be more than 1 and less than 50.\n");
      inputs_nr[1] = '\0';      // 1 <= r <= 50
      inputs_nr[0] = '\0';
    }
  }



  
  for(loop1 = 0; loop1 < 50; loop1++){  // get <p c>

    printf("input 'p c'[%d]\n", loop1 + 1);
    scanf("%d %d", &loop2, &loop3);

    inputs_shuffle[loop1][0] = loop2;
    inputs_shuffle[loop1][1] = loop3;

    
    if((inputs_shuffle[loop1][0] + inputs_shuffle[loop1][1]) > (inputs_nr[0] + 1)){
      printf("(p + c) must be less than (%d + 1)\n", inputs_nr[0]);
      loop1--;   //  (p + c) must be less than (n + 1).
    }
    else if((inputs_shuffle[loop1][0] == 0) && (inputs_shuffle[loop1][1] == 0)){
      break;     //  if ((p == 0) && (c == 0)), escape this loop.
    }
  }

  for(loop1 = 0; loop1 < 52; loop1++){  // make the stack
    if(inputs_nr[0] != 0){
      stack[loop1] = inputs_nr[0];
      inputs_nr[0]--;
    }
    else       stack[loop1] = '\0';
  }
  // stack[0], stack[1], stack[2], .......
  //       n ,      n-1,      n-2, .......

  loop1 = 0;

  while(((inputs_shuffle[loop1][0] != 0) && (inputs_shuffle[loop1][1] != 0)) && loop1 != 51){

    for(loop2 = 0; loop2 < (inputs_shuffle[loop1][0] - 1); loop2++){ //
      tmp[loop2] = stack[loop2];
    }

    for(loop3 = 0; loop3 < inputs_shuffle[loop1][1]; loop3++, loop2++){
      stack[loop3] = stack[loop2];
    }

    for(loop2 = 0; loop2 < (inputs_shuffle[loop1][0] - 1); loop2++, loop3++){
      stack[loop3] = tmp[loop2];
    }

    for(loop2 = 0; loop2 < 52; loop2++){
      tmp[loop2] = '\0';
    }

    loop1++;
  }

  printf("%d\n", stack[0]);


  return 0;

}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m;
    while (true) {
        cin >> n >> m;
        if (!n && !m) break;
        int p, c;
        vector<int> a(n);
        vector<int> b;
        for (int i = 0; i < n; ++i) {
            a[i] = n-i;
        }
        for (int i = 0; i < m; ++i) {
            cin >> p >> c; --p; --c;
            for (int j = p; j < p+c+1; ++j) {
                b.push_back(a[j]);
            }
            for (int j = 0; j < p; ++j) {
                b.push_back(a[j]);
            }
            for (int j = p+c+1; j < n; ++j) {
                b.push_back(a[j]);
            }
            a = b;
            b.clear();
        }
        cout << a[0] << endl;
    }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define rep(i, n) for(int i = 0;i < n;i++)
#define repb(i, n) for(int i = n;i >= 0;i--)
#define reps(i, m, n) for(int i = m;i < n;i++)
#define repsb(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

int main(){
	int n,p,c,r;
	while(true)
	{
		cin>>n>>r;
		if(n==0)	return 0;
		int b[50];
		rep(i,n){
			b[i]=n-i;
		}
		rep(s,r){
			int a[50],j;
			cin>>p>>c;
			for(j=0;j<c;j++){
				a[j]=b[c+j-1];
			}
			for(;j<p+c-1;j++){
				a[j]=b[j-c];
			}
			for(;j<n;j++){
				a[j]=b[j];
			}
			rep(t,n){
				b[t]=a[t];
			}
		}
		cout<<b[0]<<endl;
	}

	return 0;
}

C++: #include <iostream>
#include <queue>
#define INF (2<<29)
using namespace std;

typedef struct _node {
    _node* next;
    int n;
} Node;

Node* h;
int n,r,p,c;

Node* initNode(){
    Node* head = (Node*)malloc(sizeof(Node));
    head->n = n;
    Node* bef;
    bef = head;
    for(int i = n-1; i >= 1; i--){
        Node* tmp = (Node*)malloc(sizeof(Node));
        tmp->n = i;
        bef->next = tmp;
        bef = tmp;
    }
    return head;
}

// void freeNode(Node* n){
//     if(n->next != NULL) freeNode(n->next);
//     free(n);
// }

void pc(){
    Node *n1,*n2,*n3,*n4;
    // cout<<"[INFO]SHUFFLE-BEGIN"<<endl;
    if(p==1 && c==n) return;
    n1 = h;
    for(int i = 0; i < p-2; i++){ //p-1??????=n1
        n1 = n1->next;
    }
    n2 = n1->next; //p??????=n2
    
    // cout<<"p = "<<n2->n<<endl;
    
    n3 = n1;
    for(int i = 0; i < c; i++){ //p+c??????=n3
        n3 = n3->next;
        // cout<<"hoge"<<endl;
    }
    n4 = n3->next;
    n1->next = n4;
    n3->next = h;
    h = n2; //head???n2???
    // cout<<"[INFO]SHUFFLE-END"<<endl;
}

int main(void){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    for(;;){
        cin>>n>>r;
        if(n==0 && r==0) break;
        h = initNode();
        for(int i = 0; i < r; i++){
            cin>>p>>c;
            // cout << "p=" << p << ",c=" << c << endl;
            pc();
        }
        cout<<h->n<<endl;
        // cout<<"??????"<<endl;
    }

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<string> split(const string& str, char delimi) {
    vector<string> elem;
    string tmp;
    for (int i = 0; i < str.length(); ++i) {
        char c = str[i];
        if (c == delimi) {
            if (!tmp.empty()) {
                elem.push_back(tmp);
            }
            tmp.clear();
        } else {
            tmp += c;
        }
    }
    if (!tmp.empty()) {
        elem.push_back(tmp);
    }
    return elem;
}
int main() {
    while(1) {
        string str;
        getline(cin, str);
        vector<string> line = split(str, ' ');
        int n = atoi(line[0].c_str());
        if (n == 0)
            break;
        int r = atoi(line[1].c_str());
        int card[n];
        for (int i = 0, num = n; i < n; ++i, --num) {
            card[i] = num;
        }
        for (int i = 0; i < r; ++i) {
            string str;
            getline(cin, str);
            vector<string> line = split(str, ' ');
            int p = atoi(line[0].c_str());
            int c = atoi(line[1].c_str());
            rotate(card, card + p - 1, card + p + c - 1);
        }
        cout << card[0] << endl;
    }
}

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

int card[1000], tmp[1000], n, r;
int main()
{
loop:
  cin >> n >> r;
  if(!(n || r))
    return 0;
  for(int i = n; i > 0; i--)
    card[n - i] = i;
  for(int i = 0; i < r; i++)
  {
    int c, p;
    cin >> p >> c;
    for(int j = 0; j < p - 1; j++)
      tmp[j] = card[j];
    for(int j = 0; j < c; j++)
      card[j] = card[j + p - 1];
    for(int j = 0; j < p - 1; j++)
      card[j + c] = tmp[j];
  }
  cout << card[0] << endl;
  goto loop;
}