Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		n, _ := strconv.Atoi(chunks[0])
		r, _ := strconv.Atoi(chunks[1])
		cards := make([]int, n, n)
		for i := 0; i < n; i++ {
			cards[i] = n - i
		}
		for i := 0; i < r; i++ {
			sc.Scan()
			chunks := strings.Split(sc.Text(), " ")
			p, _ := strconv.Atoi(chunks[0])
			c, _ := strconv.Atoi(chunks[1])
			block := make([]int, c, c)
			for j := 0; j < c; j++ {
				block[j] = cards[p+j-1]
			}
			for j := p - 2; j >= 0; j-- {
				cards[j+c] = cards[j]
			}
			for j := 0; j < c; j++ {
				cards[j] = block[j]
			}
		}
		fmt.Println(cards[0])
	}
}

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

struct list{
  int number;
  list *next;
};

void Insertlist(list **ptr, int newnumber);
void Traverselist(list *ptr);


void Insertlist(list ** ptr, int newnumber){
  if( *ptr == NULL || (*ptr)->number < newnumber){
    list *newcell;
    newcell = (list *)malloc(sizeof(list));
    newcell->number = newnumber;
    newcell->next = *ptr;
    *ptr = newcell;
  }else{
    Insertlist(&(*ptr)->next, newnumber);
  }
}

void Traverselist(list *ptr){
  while(ptr!= NULL){
    cout << ptr->number << " \n";
    ptr = ptr->next;
  }
}


int main(){

  int n, r;

  while( cin >> n >> r ){

    if( n == 0 && r == 0) break;

    list *root = NULL;
    for(int i = n ; i > 0 ; i--){
      Insertlist(&root,i);
    }
    //       Traverselist(root);    

    while( r ){
      int p,c;
      cin >> p >> c;

      list *ptr1 = root, *ptr2 = root,*ptr3,*ptr4;

	for(int i = 0 ; i < p-2; i++)
	  ptr1 = ptr1->next;
	if(p > 1)
	  ptr2 = ptr1->next;
	ptr3 = ptr2;
	for(int i = 0; i < c-1 ; i++)
	  ptr3 = ptr3->next;
	ptr4 = ptr3->next;

	if(p>1){
	  ptr1->next = ptr4;
	  ptr3->next = root;
	  root = ptr2;
	}
	//   Traverselist(root);    
	r--;
    }
    cout << root->number << endl;
    
  }
  return 0;
}

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

using namespace std;

int main(void){
	int p,c;

	for(int n,r;cin >> n >> r,n||r;){
		string card;

		for(int i=0;i<n;i++)
			card+=(n-i+0x30);

		for(int i=0;i<r;i++){
			cin >> p >> c;
			if(p!=1)
				card = card.substr(p-1,c)+card.substr(0,p-1)+card.substr(p+c-1);
		}

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

	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

   while(1){

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

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

C++: #include<cstdio>
using namespace std;
int num1[50],num2[50];
void sets(int N);
void change(int p,int c);
int main()
{
    int N,r,i,j,p,c;
    for(;scanf("%d%d",&N,&r),N+r!=0;)
    {
        sets(N);
        for(i=0;i<r;i++)
        {
            scanf("%d%d",&p,&c);
            change(p,c);
        }
        printf("%d\n",num2[0]);
    }
    return 0;
}
void sets(int N)
{
    for(int i=0,j=N;i<N;i++,j--)
    {
        num1[i]=j;
    }
}
void change(int p,int c)
{
    int i;
    for(i=0;i<p-1;i++)num2[c+i]=num1[i];
    for(i=0;i<c;i++)num2[i]=num1[p-2+i];
}

C++: #include<stdio.h>

int main(){
    while(1){
        int n,r;
        int table[50];
        scanf("%d%d", &n, &r);
        if(n == 0 && r==0){
            return 0;
        }
        for (int i=0; i<n ; i++) {
            table[i]=n-i;
        }
        for(int i=0; i<r; i++){
            int p,c;
            int work[50];
            scanf("%d%d", &p,&c );
            for(int j=0; j<c; j++){
                work[j]=table[p-1+j];
            }
            for(int j=0; j<p-1; j++){
                work[c+j]=table[j];
            }
            for(int j=p-1+c; j<n; j++){
                work[j]=table[j];
            }
            for(int j=0; j<n; j++){
                table[j]=work[j];
            }
        }
        printf("%d\n", table[0] );
    }
}

C++: #include<iostream>
using namespace std;
int main(){

  int n, r, p, c, d[50], e[50];

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

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;

int main(){

	int n,r,c,p,ar[50];
	while(cin>>n>>r){
		if(n==0 && r==0) return 0;
		for(int i=0; i<n; i++) ar[i]=n-i;
		for(int i=0; i<r; i++){
			cin>>p>>c;
			int t1[50],t2[50];
			for(int i=0; i<p-1; i++){
				t1[i] = ar[i];
			}
			for(int i=p-1; i<p+c-1; i++){
				t2[i-p+1] = ar[i];
			}
			for(int i=0; i<c; i++){
				ar[i]=t2[i];
			}
			for(int i=c; i<p+c-1; i++){
				ar[i]=t1[i-c];
			}
		}
		cout<<ar[0]<<endl;
	}

	return 0;
}

C++: #include<iostream>

#define R input[0][1]

using namespace std;

int input() {
	int input[51][2];
	cin >> input[0][0] >> input[0][1];								//まずnとr
	if (input[0][0] == 0 && input[0][1] == 0) {
		return 0;
	}
	for (char pos = 1; pos <= input[0][1]; pos++) {					//r回のシャッフルの仕方を入力
		cin >> input[pos][0] >> input[pos][1];
	}																//ここまで入力

	/*シャッフルもどし*/
	int whtop = 1;													//最後一番上にいるカードは、今何番目にいる？
	if (R==0)return input[0][0];									//一回もシャッフルしないならコレ
	while (input[0][1] != 0) {	
		if (whtop <= input[R][1]) whtop = whtop + input[R][0] - 1;
		else if ((input[R][0] + input[R][1] - 1) < whtop) whtop = whtop;
		else whtop = whtop - input[R][1];
		R--;
	}
	return input[0][0] - whtop + 1;

}


int main()
{
	while (1) {
		int check;
		check = input();
		if (check == 0)break;
		else cout << check << endl;
	}
}

C++: #include <iostream>
#include<bits/stdc++.h>
using namespace std;
int n,m,a,b;
vector<int> v,u;
int main(void){
    while(1){
    cin>>n>>m;
    if(n==0&&m==0)return 0;
    for(int i=n;i>0;i--){
        v.push_back(i);
    }
    for(int i=0;i<m;i++){
        cin>>a>>b;
        a--;
        for(int i=n-1;i>a+b-1;i--)u.push_back(v[i]);
        for(int i=a-1;i>=0;i--)u.push_back(v[i]);
        for(int i=a+b-1;i>=a;i--)u.push_back(v[i]);
        v={};
        for(int i=n-1;i>=0;i--)v.push_back(u[i]);
        u={};
    }
    cout<<v[0]<<endl;
    v={};
    }
}

C++: #include <stdio.h>
#include <iostream>

using namespace std;

void suffle (int a, int b, int t[]) {
	int kari[50];
	int kari2[50];
	for (int i = 0; i < a-1; i++) {
		kari[i] = t[i];
	}
	for (int i = 0; i < b; i++) {
		kari2[i] = t[a-1+i];
	}

	for (int i = 0; i < b; i++) {
		t[i] = kari2[i];
	}

	for (int i = 0; i < a-1; i++) {
		t[b+i] = kari[i];
	}
	return;
}

int main() {
	int yama[50];
	int k,r;
	int a,b;

	while (cin >> k >> r) {
		if (k == 0 && r == 0) {
			break;
		}

		for (int i = 0; i < k; i++) {
			yama[i] = k-i;
		}

		for (int i = 0; i < r; i++) {
			cin >> a >> b;
			suffle(a,b,yama);
		}
		cout << yama[0] << endl;
	}
	return 0;
}

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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

signed main(){
    while(true){
        int n, r; cin >> n >> r;
        if(n == 0)break;
        vector<int> l(n+1);
        for(int i = 1; i <= n; i++){
            l[i] = i;
        }
        for(int i = 0; i < r; i++){
            int p,c; cin >> p >> c;
            int b = n-p-c+2;
            for(int j = 0; j < c; j++){
                l.push_back(l[b]);
                l.erase(l.begin() + b);
            }
        }
        cout << l.back() << endl;
    }

    return 0;
}