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>

using namespace std;

int main(){
  int maisu[50];
  int katto;
  int swap[50];
  int p,c;
  int i,j=0;

  for(i=0; i<50; i++){
    maisu[i] = i;
  }

  cout << maisu[0] << endl;

  cin >> katto;
  
  while(j <= katto){
  
    while(true){
      scanf("%d%d",&p,&c);
      if(p == 0 && c == 0){
	break;
      }
      for(i=0; i<c; i++){  
	swap[i] = maisu[i + p-1];
      }
      for(i = 0; i<p-1; i++){
	swap[i+c] = maisu[i];
      }
      for(i=0;i<p+c-1; i++){
	maisu[i] = swap[i];
      }
    }
    if(p == 0 && c == 0){
	break;
    }
  }
    cout << maisu[0] << endl;
 
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;


void shuffle(int p, int c, int A[]) {
    rotate(A, A+p-1, A+p+c-1);
}

int main()
{   
    int n, r;
    while (cin >> n >> r && n > 0) {

        int p, c;
        int A[n];

        /* 山札を作成 */

        for (int i = 0; i < n; i++) 
            A[i] = i+1;
            
        reverse(A, A+n);

        /* シャッフルする */

        for (int i = 0; i < r; i++) {
            cin >> p >> c;
            shuffle(p, c, A);
        }

        /* 山札の一番上を表示 */
        
        cout << A[0] << endl;
    }
}

C++: 
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)

int main(){
  int n, r;
  while(cin >>n >>r && n){
    vector<int> v;
    for(int i = n; i > 0; i--) v.push_back(i);

    REP(j, r){
      int p, c;
      cin >>p >>c;
      vector<int> next;
      for(int i = 0; i < c; i++) next.push_back(v[p - 1 + i]);
      for(int i = 0; i < p - 1; i++) next.push_back(v[i]);
      for(int i = p + c - 1; i < v.size(); i++) next.push_back(v[i]);
      v = next;
    }
    cout <<v[0] <<endl;
  }
  return 0;
}

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

int main(){
	int n,r;
	while((cin >> n)&&(cin >> r)&&(n!=0)&&(r!=0)){
		int a[n];
		int cnt=n;
		for(int i=0;i<n;i++){
			a[i] = cnt;
			cnt--;
			//cout << "a[" << i << "]" << a[i] << endl;
		}
		int p,c;
		//cout << endl;
		for(int i=0;i<r;i++){
			cin >> p;
			cin >> c;
			int b[p+c];
			//cout << p << endl;
			//cout << c << endl;
			//cout << endl;
			if(n!=c){
				for(int j=0;j<p;j++){
					b[j+c] = a[j];
				}
				for(int j=0;j<c;j++){
					b[j] = a[p+j-1];	
				}
				for(int j=0;j<p+c;j++){
					a[j] = b[j];	
					//cout << "a[" << j << "]" << a[j] << endl;
				//	cout << "b[" << j << "]" << b[j] << endl;
				}
			}
		}
		cout << a[0] << endl;
	}
}

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

int main(){
	int n,r;
	while(cin >> n >> r){
		if(n==0 && r==0) break;
		int card[51];
		bool flag[51];
		for(int i=0; i<n; i++){
			card[i] = n-i;
			flag[i]=false;
		}
		for(int j=0; j<r; j++){
			int p,c;
			cin >> p >> c;
			vector<int> change;
			for(int i=p-1; i<p-1+c; i++){
				change.push_back(card[i]);
				flag[card[i]]=true;
			}
			for(int i=0; i<p-1; i++){
				change.push_back(card[i]);
				flag[card[i]]=true;
			}
			for(int i=p-1+c; i<n; i++){
				change.push_back(card[i]);
			}
			int count=0;
			vector<int>::iterator it = change.begin();
			while(it!=change.end()){
				card[count] = *it;
				count++;
				it++;
			}
			for(int i=0; i<n; i++) cout << card[i] << " ";
			cout << endl;
		}
		cout << card[0] << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
	int n, r;

	while (cin >> n >> r && (n > 0 && r > 0)) {
		int card[51];

		for (int i = 1; i <= n; i++) {
			card[i] = n - i + 1;
		}

		int p, c;
		for (int i = 0; i < r; i++) {
			cin >> p >> c;

			int temp[50];
			for (int j = 0; j < c; j++) {
				temp[j] = card[p + j];
			}

			for (int j = p - 1; j >= 1; j--) {
				card[j + c] = card[j];
			}

			for (int j = 0; j < c; j++) {
				card[j + 1] = temp[j];
			}
		}

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

	return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
	int n,r;
	while(1){
		cin>>n>>r;
		if(n==0&&r==0){
			break;
		}

		int *a;
		a = new int[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 *data1,*data2;
			data1 = new int[p];
			data2 = new int[c];

			for(int i=0;i<p-1;i++){
				data1[i]=a[i];
			}
			for(int i=0;i<c;i++){
				data2[i]=a[i+p-1];
			}
			for(int i=0;i<c;i++){
				a[i]=data2[i];
			}
			for(int i=0;i<p-1;i++){
				a[i+c]=data1[i];
			}
		}

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

C++: #include <iostream>
using namespace std;
int main()
{
    int n,r,p,c;
    int card[100],temp[100];
    
    while(cin >> n >> r,n!=0&&r!=0){
        for(int i=0;i<n;i++) card[i] = n-i;
        for(int i=0;i<r;i++){
            cin >> p >> c;
            for(int i=0;i<c;i++) temp[i] = card[p-1+i];
            for(int i=0;i<p-1;i++) temp[i+c] = card[i];
            for(int i=0;i<p+c-1;i++) card[i] = temp[i];
        }
        cout << card[0] << endl;
    }

    return(0);
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main()
{
    int n, r;
    while (cin >> n >> r, n|r) {
        vi v[2];
        rep(i, n){
            v[0].pb(n-i);
            v[1].pb(n-1);
        }
        rep(i, r) {
            int p, c;
            cin >> p >> c;
            int j = 0;
            for (; j < c; j++){
                v[(~i)&1][j] = v[i&1][j+p-1];
            }
            for (; j < c + p-1; j++){
                v[(~i)&1][j] = v[i&1][j-c];
            }
            for (; j < n; j++){
                v[(~i)&1][j] = v[i&1][j];
            }
        }
        cout << v[r&1][0] << endl;
    }
    return 0;
}