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

int n, r, p, c;
int h[51];

int main() {
  while(cin>>n>>r,n|r) {
    for(int i=0;i<n;++i) {
      h[i+1] = i+1;
    }
    for(int i=0;i<r;++i) {
      cin>>p>>c;
      rotate(h+1, h+p, h+p+c);
    }
    cout << h[1] <<endl;
  }
  return 0;
}

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

using std::cout;
using std::cin;
using std::endl;
using std::vector;

void initStatus(vector<int> &v) {
    int size = v.size();
    for (int i = 0; i < size; i ++) {
        v[i] = size - i;
    }
}

vector<int> change(vector<int> &v, int n, int p, int c) {
    vector<int> v1(p - 1);
    vector<int> v2(c);
    vector<int> v3(n - (p - 1) - c);

    int count_v1 = 0;
    int count_v2 = 0;
    int count_v3 = 0;

    for (int i = 0; i < n; i ++) {
        if (i < p - 1) {
           v1[count_v1] = v[i]; 
           count_v1 ++;
        } else if (i > p + c - 2) {
            v3[count_v3] = v[i];
            count_v3 ++;
        } else {
            v2[count_v2] = v[i];
            count_v2 ++;
        }
    }
        std::copy(v1.begin(),v1.end(),std::back_inserter(v2));
        std::copy(v3.begin(),v3.end(),std::back_inserter(v2));
    return v2;
}

int shuffle(vector<int> &v, int n, int r) {
    int p;
    int c;
    for (int i = 0; i < r; i ++) {
        cin >> p >> c; 
        v = change(v, n, p, c);
    }
}

int main() {
    int n;
    int r;
    cin >> n >> r; 
    while (n != 0 && r != 0) {
        vector<int> v(n);
        initStatus(v);
        shuffle(v, n, r);
        cout << v[0] << endl;
        cin >> n >> r; 
    }
    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cmath>
#include <deque>

using namespace std;

int n=0;//num
int r=0;//round

//just simulate
int main(int args, char *argc[]){
  while(cin>>n>>r){
    if(n==0 && r==0)
      return 0;
    deque<int> cards;
    for(int i=0;i<n;i++)
      cards.push_front(i+1);

    //test
    /*for(int i=0;i<n;i++)
      printf("[%d]:%d ",i,cards[i]);
      puts("");
     */

    int a,b;
    for(int i=0;i<r;i++){
      cin>>a>>b;
      //for(int ix=a-1;ix<=a+b-2;ix++){
      for(int ix=a+b-2;ix>=a-1;ix--){
        int temp=cards[a+b-2];
/*        printf("i:%d ix:%d temp:%d\n",i,ix,temp);*/
        cards.erase(cards.begin()+(a+b-2));
        cards.push_front(temp);
      }
/*      printf("i--%d a:%d b:%d -- ",i,a,b);
      for(int i=0;i<n;i++)
        printf("[%d]:%d ",i,cards[i]);
      puts("");*/
    }

/*    cout<<"last\n";
    for(int i=0;i<n;i++)
      printf("[%d]:%d ",i,cards[i]);
    puts("");*/
    cout<<cards[0]<<endl;

    }
    return 0;
  }

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

void rengeSwap(int b,int e,int* ans){
  int tmp[b];
  b--;
  for(int i=0;i<b;i++){
    tmp[i]=ans[i];
  }
  for(int i=b;i<b+e;i++){
    ans[i-b]=ans[i];
  }
  for(int i=e;i<b+e;i++){
    ans[i]=tmp[i-e];
  }
}

int main(){
  int n,r;
  while(cin>>n>>r,n){
    int ans[n];
    for(int i=0;i<n;i++){
      ans[i]=n-i;
    }

    for(int i=0;i<r;i++){
      int b,e;
      cin>>b>>e;
      rengeSwap(b,e,ans);
    }
cout << ans[0] << endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define DEC(i, s) for (int i = (s); i >= 0; i--)

#define SIZE(v) (int)((v).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())

int n, r;
int seq[100][100];

int main() {
  while (cin >> n >> r, n|r) {
    REP(i, n) { seq[0][i] = n - i; }
    REP(i, r) {
      int p, c;
      cin >> p >> c;
      p--;
      int index = 0;
      REP(j, c) {
        seq[i + 1][index++] = seq[i][j + p];
      }
      REP(j, n) {
        if (j >= p && j < p + c) { continue; }
        seq[i + 1][index++] = seq[i][j];
      }
    }
    printf("%d\n", seq[r][0]);
  }
}

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


int card[50];
struct CUT{
  int p;
  int c;
};

CUT cut[51];
int swap_p[50];
int swap_c[50];
int n,r;
void solve(){
  for(int i = 0; i < n; i++){
    card[i] = n - i;
  }

  for(int i = 0; i < r ; i++){
    for(int x = 0; x < n; x++){
      cout << card[x] << " ";
    }
    cout << endl;
    for(int j = 0; j < cut[i].p; j++) swap_p[j] = card[j];
    for(int k = 0; k < cut[i].c; k++) swap_c[k] = card[cut[i].p + k - 1];
    for(int l = 0; l < cut[i].p + cut[i].c - 1;l++){
      if(cut[i].c > l)  card[l] = swap_c[l] ;
      else              card[l] = swap_p[ l - cut[i].c ];
    }
  }
  cout << card[0] << endl;
  return ;
}



int main(){
  while(true){
    cin >> n >> r;
    if(n == 0 && r == 0) break;
    for(int input = 0; input < r; input++){
      cin >> cut[input].p >> cut[input].c ;
    }
    solve();
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int d[51];
int cop[51];
int main(void){
  int n,r;
  while(cin>>n>>r){
    if(n==0) break;
    REP(i,n) d[i] = n-i;
    REP(i,r){
      int p,c;
      cin>>p>>c;
      REP(j,c)cop[j] = d[p-1+j];
      for(int j=p-2; j>=0; j--){
        d[j+c] = d[j];
      }
      REP(j,c) d[j] = cop[j];
    }
    cout<<d[0]<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
    int n,r;
    while(scanf("%d %d",&n,&r),n!=0) {
        vector<int> v;
        for(int i=n;i>=1;i--) v.push_back(i);
        for(int i=0;i<r;i++) {
            vector<int> nv;
            int p,c;
            scanf("%d %d",&p,&c);p--;
            for(int i=0;i<c;i++) {
                nv.push_back(v[p+i]);
            }
            for(int i=0;i<p;i++) nv.push_back(v[i]);
            for(int i=p+c;i<n;i++) nv.push_back(v[i]);
            v=nv;
        }
        printf("%d\n",v[0]);
    }
}