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>
#include <cstdlib>
#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>
using namespace std;

int main(){
	
	int n,r;
	while(cin>>n>>r){
		if(n!=r!=0){
		int h[51]={0},m[51]={0};
		int p,d;
		for(int i=0;i<n;i++)
			h[i+1]=n-i;
		while(r>0){
			cin>>p>>d;
			int j=d;
			for(int i=p+d-1;i>=p;i--)
				m[j--]=h[i];
			for(int i=p-1;i>0;i--)
				h[i+d]=h[i];
			for(int i=d;i>0;i--)
				h[i]=m[i];
			r--;
	}
			cout<<h[1]<<endl;
	}
	else
		break;
	}
	
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
  int n=1,r=1,p,c;
  vector<int> deck,temp,ans;

  while(1){
    cin >> n >> r;
    if(n==0&&r==0)break;
    for(int i=n; i>0; --i)deck.push_back(i); //???????????????
    for(int i=0; i<r; ++i){
      cin >> p >> c;
      copy(deck.begin()+p-1,deck.begin()+p+c-1,back_inserter(temp));
      deck.erase(deck.begin()+p-1,deck.begin()+p+c-1);
      copy(deck.begin(),deck.end(),back_inserter(temp));
      deck=temp;
      temp.clear();
    }
    ans.push_back(deck[0]);
    deck.clear();
  }
  for(auto x: ans)cout << x << endl;
  return 0;
}

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

int main(){
  int n,r, start, end;
  vector<int> ans;
  cin >> n >> r;
  while(n||r){
    vector<int> data(n);
    for(int i = 0; i <n;i++){
      data[i] = n-i;
    }
    for(int j = 1; j <= r ; j++){
      cin >> start >> end;
      for(int k = 0; k < end;k++){
        int a = data[start+k-1];
        for(int forth = start-1; forth > k; forth--){
          data[k+forth] = data[k+forth-1];
        }
        data[k] = a;
      }
    }
    ans.push_back(data[0]);
    cin >> n >> r;
  }
  for(int i =0;i<ans.size();i++){
    cout << ans[i] << endl;
  }
}

C++: 
#include<bits/stdc++.h>
using namespace std;
int x[100];
int y[100];
int card [100];
int n,r;
int ans[1000];
int counter;
bool input(){
    for(int i=0;i<100;i++){
    x[i]=0;
    y[i]=0;
    }
    cin >>n>>r;
    for(int i=0;i<r;i++){
    cin>>x[i]>>y[i];
    }
    if(n==0){
    return false;
    }
    else{
     return true;
    }
}
void solve(){
    for(int i=0;i<100;i++){
        card[i]=i+1;
    }
    for(int i=0;i<r;i++){
        for(int k=0;k<y[i];k++){
            int a=card[x[i]+y[i]-2];
            for(int j=x[i]+y[i]-1;j>0;j--){
                card[j]=card[j-1];
            }
            card[0]=a;
            
        }
    for(int j=1;j<=y[i]/2;j++){
int remainder=card[j];
card[j]=card[y[i]-j];
card[y[i]-j]=remainder;
}
    }
 
    ans[counter]=card[0];
 counter+=1;
}
  
  
  
int main (){
counter=0;
    while(input()){
    solve();
    }
for(int j=0;j<=counter;j++){
cout<<ans[counter]<<endl;
}
return 0;
}

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

using namespace std;
int main(void){
   int field[3][51],n,r;
   while(scanf("%d%d",&n,&r),n+r){
      for(int i = 0;i < n;i++){field[0][i] = n-i-1;}
      for(int i = 0;i < r;i++){
         int p,c;scanf("%d%d",&p,&c);
         for(int j = 0;j < p-1;j++){
            field[2][j] = field[0][j];
         }
         for(int j = 0;j < c;j++){
            field[1][j] = field[0][p-1+j];
         }
         for(int j = 0;j < c;j++){
            field[0][j] = field[1][j];
         }
         for(int j = 0;j < p-1;j++){
            field[0][c+j] = field[2][j];
         }
      }
      printf("%d\n",field[0][0]+1);
   }
   return 0;
}

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

using namespace std;

int main(){
	while(true){
		vector<int> yama;
		int n,r;
		cin >> n >> r;
		if(n==0&&r==0)return 0;
		for(int i=n;i>0;i--){
			yama.push_back(i);
		}
		for(int i=0;i<r;i++){
			int p,c;
			vector<int> next;
			cin >> p >> c;
			p--;
						
			for(int k=p;k<p+c;k++){
				next.push_back(yama[k]);
			}
			for(int k=0;k<p;k++){
				next.push_back(yama[k]);
			}
			for(int k=p+c;k<n;k++){
				next.push_back(yama[k]);
			}
			yama=next;
		}
		cout << yama[0] <<endl;
	}
}