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 <vector>
using namespace std;

//?±±?????????????????¢??°???????±±???????±±????????°n???p?????????????????????c???                       
void shuffle(vector<int> &yama, int n, int p, int c);


int main(){
  int n, r;
  int p, c;
  vector<int> yama, v;

  cin >> n;
  cin >> r;

  while(n != 0 && r != 0){
    //?±±??????????????????                                                            
    yama.clear();
    for(int i = 0, j = n; i < n; i++, j--){
      yama.push_back(j);
    }
    //?????£?????????                                                                
    for (int i = 0; i < r; i++){
      cin >> p;
      cin >> c;
      shuffle(yama, n, p, c);
    }
    //???????????????????¨????                                                          
    v.push_back(yama.front());

    cin >> n;
    cin >> r;
  }
  for(int i = 0; i < v.size(); i++){
    cout << v[i] << endl;
  }
  cout << endl;
}
void shuffle(vector<int> &yama, int n, int p, int c){
  int tmp;

  for(int i = 0;i < c; i++){
    tmp = yama[p-1+c-1];
    yama.erase(yama.begin()+p-1+c-1);
    yama.insert(yama.begin(), tmp);
    for(int j = 0; j < yama.size(); j++){
      cout << yama[j] << " ";
    }
    cout << endl;

  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,r;
  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++){
      int p,c;
      cin >> p >> c;

      vector<int> v1,v2;
      for(int j=0; j<p-1; j++) v1.push_back(a[j]);
      for(int j=0; j<c; j++) v2.push_back(a[j+p-1]);
      for(int j=0; j<c; j++) a[j] = v2[j];
      for(int j=0; j<p-1; j++) a[j+c] = v1[j];
    }
    cout << a[0] << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int a[51]={};
  int st[51]={};
  int n,r;
  int p,c;
  while(1){
    //in
    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=0;j<n;j++){
	st[j]=a[j];
      }
      for(int j=0;j<c;j++){
	a[j]=st[p-1+j];
      }
      for(int j=c;j<c+p;j++){
	a[j]=st[j-c];
      }
    }
    cout << a[0] << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
int main(void)
{
	int n, r, p, c;
	int num[1000][50];
	int ans[1000];
	int i, t,k,l;
	int change;
	int re[1000];
	n = r = 1;
	for (i = 0; i < 1000; i++)
	{
	scanf("%d %d", &n, &r);
	if (n == 0 && r == 0)
	{
		break;
	}
	for (t = 0; t < n; t++)
	{
		num[i][t] = n - t;
	}
	for (t = 0; t < r; t++)
	{
	
		scanf("%d %d", &p, &c);
		for (l = 0; l < n ; l++)
		{
			re[l] = num[i][l];
		}
		for (k = 0; k < c; k++)
		{
			change = re[p-1+k];
			num[i][k] = change;
		}
		for (k = 0; k < p - 1; k++)
		{
			change = re[k];
			num[i][c + k] = change;
		}
			
	}
	ans[i] = num[i][0];
	}
	for (t = 0; t < i; t++)
	{
		printf("%d\n", ans[t]);
	}

	
}

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

int main()
{

  int n, r, p, c;
  
 while(cin >> n >> r, n){
        int s[n];
	
        for(int i = 0; i < n; i++){   // s??????????????????????????\??????
            s[i] = n - i;
        }
	
        for(int i = 0; i < r; i++){
       
            cin >> p >> c;
            rotate(s, s + p - 1, s + p + c - 1);	    
        }
	
        cout << s[0] << endl;
    }

}

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

int main(){

  while(1){

    int n, p, c, r, yamahuda[51] = {0}, ue[51] = {0}, shita[51] = {0}, cnt = 1;

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

    for(int i = n; i >= 1; i--){
      yamahuda[n-i+1] = i;
    }

    for(int i = 1; i <= r; i++){
      cin >> p >> c;
      for(int j = 1; j < p; j++){
	ue[j] = yamahuda[j];
	//cout << ue[j];
      }
      //cout << endl;
      cnt = 1;
      for(int s = p; s < p+c; s++){
	shita[cnt] = yamahuda[s];
	//	cout << shita[cnt];
	//cout << cnt;
	cnt++;
      }
      //cout << endl;
      // cnt = 1;
      for(int l = 1; l < cnt; l++){
	yamahuda[l] = shita[l];
	//	cout << shita[l];
      }
      //  cout << endl;
      
      for(int m = 1; m < p; m++){
	yamahuda[cnt] = ue[m];
	cnt++;
      }
      // for(int k = 1; k <= n; k++) cout << yamahuda[k];
      //cout << endl;
    }
     cout << yamahuda[1] << endl;
   
    
  }

  return 0;
}

C++: #include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
using namespace std;

typedef long long int ll; 
typedef pair<int,int> Pii;

vector<int> ans;
vector<int> col;



void changeCol(int p,int c){
    vector<int> toDOWN;
    vector<int> toUP;

    for (int i = 1; i <= p-1; i++)toDOWN.push_back(col[i]);
    for (int i = p; i <= p+c-1; i++)toUP.push_back(col[i]);

    for(int i=1;i<=c;i++)col[i]=toUP[i-1];
    for(int i=c+1,j=0;i<p+c;i++,j++)col[i]=toDOWN[j];
}


int main(){
int n,r;
int tmp1,tmp2;
    while(1){
        cin>>n>>r;
        if(n==0&&r==0)break;
        col.clear();
        for(int i=0;i<=n;i++)col.push_back(i);
        for (int j = 0; j < r; j++){
            cin>>tmp1>>tmp2;
            changeCol(tmp1,tmp2);
        }
        ans.push_back(n+1-col[1]);
    }
     for(int i=0;i<ans.size();i++){
        cout<<ans[i]<<"\n";
    }
    return 0;
}

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

using namespace std;

vector<int> cut(vector<int>& card, int ft, int noc)
{
	vector<int>::iterator itr;
	for(itr = card.begin(); itr != card.end(); ++itr){
		if(*itr < ft){
			*itr += noc;
		}else if(*itr < ft + noc ){
			*itr -= ft - 1;
		}
	}
	//for(itr = card.begin(); itr != card.end(); ++itr)
		//cout << *itr <<endl;
	//cout << endl;
	return card;
}

int main(void)
{
	int num, cut_num, top;
	vector<int>::iterator itr;

	while(1){
		cin >> num >> cut_num;
		if(num == 0 && cut_num == 0){
			break;
		}

		vector<int> card;
		for(int i = 0; i < num; i++){
			card.push_back(i + 1);
		}

		for(int i = 0; i < cut_num; i++){
			int from_top, num_of_cards;
			cin >> from_top >> num_of_cards;
			card = cut(card, from_top, num_of_cards);
		}

		itr = card.begin();
		for(int i = 0; i < num; i++){
			if(*itr == 1){
				top = i;
				break;
			}
			itr += 1;
		}
		cout << num - top << endl;

	}
	return 0;
}

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

#define rep(i, j) for(int i = 0; i < j; i++)

using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	while (1)
	{
		int n = 0, r = 0; cin >> n >> r;
		if (n == 0 && r == 0) { return 0; }
		int p = 0, c = 0;
		vector<int> bef(n + 5);
		vector<int> aft(n + 5);
		rep(i, n) 
		{
			bef[i] = n - i;
			aft[i] = n - i;
		}
		rep(i, r)
		{
			cin >> p >> c;
			rep(j, p - 1){	aft[c + j] = bef[j];	}
			rep(j, c)	{	aft[j] = bef[p - 1 + j];	}
			bef = aft;
		}
		printf("%d\n", bef[0]);
	}
	return 0;
}