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 <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


int main(){
  int n, r;

  while(cin >> n >> r){
    if(n == 0 && r == 0) return 0;

    else{
    int hana[n];
    REP(i, n) hana[i]=n-i;

    REP(j, r){
      int p, c;
      cin >> p >> c;
      int tmp[c];
      REP(i, c) tmp[i] = hana[p+i-1];
      REP(i, p-1) hana[p-2-i+c] = hana[p-2-i];
      REP(i, c) hana[i] = tmp[i];
    }
    cout << hana[0] << endl;
  }
  }
return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n||m){
    string in;
    rep(i,n)in=(char)(i+49)+in;

    rep(i,m){
      int a,b;
      cin>>a>>b;
      //cout<<in<<endl;
      in=in.substr(a-1,b)+in.substr(0,a-1)+in.substr(a+b-1);
    }
    cout<<in[0]-'0'<<endl;
  }

}

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

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

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

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);
  }
}

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);
    }
 
    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;
      } 
      r--;
    }
    cout << root->number << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,r;
  while(cin>>n>>r,n+r!=0){
    queue<int> yama;
    queue<int> x;
    queue<int> y;
    queue<int> z;
    for(int i=n;i>=1;i--)
      yama.push(i);
    for(int i=0;i<r;i++){
      int p,c;
      cin>>p>>c;
      for(int i=1;i<=p-1;i++){
	x.push(yama.front());
	yama.pop();
      }
      for(int i=1;i<=c;i++){
	y.push(yama.front());
	yama.pop();
      }
      while(!yama.empty()){
	z.push(yama.front());
	yama.pop();
      }
      while(!y.empty()){
	yama.push(y.front());
	y.pop();
      }
      while(!x.empty()){
	yama.push(x.front());
	x.pop();
      }
      while(!z.empty()){
	yama.push(z.front());
	z.pop();
      }
    }
    cout<<yama.front()<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include<vector>
#include<string.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){
    int n,r;
    while(cin>>n>>r,n,r){;
        int card[60];
        for(int i=0;i<60;i++){
            card[i]=n-i;
        }
        for(int i=0;i<r;i++){
            int p,c;
            cin>>p>>c;
            vector<int>C;
            for(int j=0;j<c;j++){
                C.push_back(card[p-1+j]);
            }
            int j;
            for(j=c+p-2;j>=c-1;j--){
                card[j]=card[j-c];
            }
            for(int k=0;k<c;k++){
                card[k]=C[k];
            }
        }
        cout<<card[0]<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main(void){
	int n, r;
	while(cin >> n >> r, n | r){
		int card[n];
		card[0] = n;
		for(int i = 1; i < n; i++)card[i] = card[i-1]-1;
		rep(i,r){
			int p, c;
			cin >> p >> c;
			int abv[p];
			for(int j = 0; j < p-1; j++){
				abv[j] = card[j];
			}
			for(int j = 0; j < c; j++){
				card[j] = card[p-1+j];
			}
			for(int j = 0; j < p-1; j++){
				card[c+j] = abv[j];
			}
		}
		cout << card[0] << endl;
	}

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main(void)
{
  while(1){
    int n, r;
    cin >> n >> r;
    if(n == 0 && r == 0)
      break;
    
    int card[n+1];
    for(int i = 1; i <= n; i++) card[i] = n - i + 1;
    // for(int i = 1; i <= n; i++) printf("%d ", card[i]);
    // puts("A");
    
    int shuf[n+1];
    shuf[0] = 0;
    for(int i = 1; i <= r; i++){
      int p, c;
      cin >> p >> c;
      
      for(int j = 0; j < c; j++){ // p~
	shuf[j+1] = card[p+j];
	//	printf("%d ", shuf[j+1]);
      }
      // printf("|");
      for(int j = 1; j < p; j++){ // 1~
	shuf[c+j] = card[j];
	//printf("%d ", shuf[c+j]);
      }
      // printf("|");
      for(int j = c + p; j <= n; j++){ //others
	shuf[j] = card[j];
	//printf("%d ", shuf[j]);
      }
      //puts("");
      for(int j = 1; j <= n; j++){ // copy
	card[j] = shuf[j];
      }
      for(int j = 1; j <= n; j++){
	//	printf("%d ", card[j]);
      }
      //puts("");
      
    }

    printf("%d\n", card[1]);
  }
  
  return 0;
}