Go: package main

import "fmt"

func main() {
	var n, r int
	fmt.Scan(&n, &r)
	for n != 0 || r != 0 {
		arr := make([]int, n)
		for i := range arr {
			arr[i] = len(arr) - i
		}

		for i := 0; i < r; i++ {
			var p, c int
			fmt.Scan(&p, &c)
			mid, top, last := arr[:p-1], arr[p-1:p-1+c], arr[p-1+c:]
			arr = append(append(append([]int{}, top...), mid...), last...)
		}
		fmt.Println(arr[0])
		fmt.Scan(&n, &r)
	}
}

C++: #include <iostream>
#include <map>
#include <deque>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n,r;
	
	while(cin >> n >> r , n){
		deque<int> card(n);
		rep(i,n)card[n-i-1]=i+1;

		rep(i,r){
			int p,c;
			cin >> p >> c;
			deque<int> t(c);
			rep(j,c)t[j] = card[p-1+j];
			rep(j,c)card.erase( remove(card.begin(),card.end(),card[p-1+j]),card.end() );
			rep(j,c)card.push_front(t[c-1-j]);
		}
		cout << card[0] << endl;
	}
}

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

int card[50];
int change1[50],change2[50];
int n,r,p,c;

int main(){

  while(1){
    cin >> n >> r;
    if(n+r==0)
      break;
    
    for(int i=0;i<n;i++)
      card[i]=n-i;
    
    for(int i=0;i<r;i++){
      cin >> p >> c;
      
      for(int j=0;j<p-1;j++)
	change1[j]=card[j];
      for(int j=0;j<c;j++)
	change2[j]=card[p+j-1];
      
      for(int j=0;j<c;j++)
	card[j]=change2[j];
      for(int j=0;j<p-1;j++)
	card[c+j]=change1[j];
    }
    
    cout << card[0] << endl;
    
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main(void) {
  int yama[51], tmp[51];

  int n, r;
  while (cin >> n >> r, (n || r)) {
    // initialization
    for (int i=0; i<n; i++) {
      yama[i] = i + 1;
    }

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

      for (int j=0; j<c; j++) {
        tmp[c-1-j] = yama[n-p-j];
      }
      for (int j=n-p+1; j<n; j++) {
        yama[j-c] = yama[j];
      }
      for (int j=0; j<c; j++) {
        yama[n-c+j] = tmp[j];
      }
    }

    cout << yama[n-1] << endl;
  }
  return 0;
}

C++: #include <stdio.h>

int main(){
    int n,r,i,j,p,c,a[51],b[51];
    while(1){
        scanf("%d %d\n",&n,&r);
        if (n==0&&r==0) break;
        for (i=1;i<=n;i++) {
            a[i]=n+1-i; 
            b[i]=n+1-i;
        }
        for (i=0;i<r;i++) {
            scanf("%d %d",&p,&c);
            for (j=1;j<=c;j++) {
                b[j]=a[j+p-1];
            }
            for (j=c+1;j<=c+p-1;j++) {
                b[j]=a[j-c];
            }
            for (j=1;j<=n;j++) {
                a[j]=b[j];
            }
        }
        
        printf("%d\n",a[1]);
        
    }
    return 0;
}

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

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long

//constant
const int MOD = 1000000009;
//const int INF = INT_MAX / 3;

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
	int n, r;
	while (cin >> n >> r, n) {
		vi st(n);
		REP(i, n)
			st[i] = n-i ;

		REP(i, r) {
			vi sw(n);
			REP(i, n)
				sw[i] = st[i];
			int p, c;
			cin >> p >> c;
			REP(j, c)
				sw[j] = st[p-1  + j];
			REP(j, p-1)
				sw[j + c] = st[j];


			REP(i, n)
				st[i] = sw[i];

		}

		cout << st[0] << endl;
	}

	return 0;
}

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

int main(){
	int n,r;
	while(cin >> n >> r, n,+r){
		int data[50], tmp[50];
		for(int i=0; i<n; i++){
			data[i]	= n-i;
			tmp[i] = n-i;
		}
		for(int i=0; i<r; i++){
			int p,c;
			cin >> p >> c;
			for(int j=0; j < p+c-1; j++){
				if(j<p-1){
					tmp[j+c] = data[j];
				}else{
					tmp[j-p+1] = data[j];
				}
			}
			for(int j=0; j<n; j++){
				data[j] = tmp[j];	
			}
		}
		cout << data[0] << endl;
	}
}

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

using namespace std;

void sort(int *x, int *y)
{
	int temp;
	temp = *x;
	*x = *y;
	*y = temp;
}

int main(void)
{
	int n, r;
	while(cin >> n >> r && n!=0 && r != 0)
	{	
		vector<int> A(n);
		for(int i = 0;i < n; i++)
		{
			A[i] = n - i;
		}

		int p, c;

		for(int i = 0; i < r; i++)
		{
			cin >> p >> c;
			vector<int> B(p);
			
			if( (p+c-1) == n)
			{
				for (int i = 0; i < n; i++)
				{
					A[i] += c;
					if(A[i] > n)
						A[i] = A[i] % n;
					if(A[i] == 0)
						A[i] = n;
				}
			}
			else
			{
				int j = 0;
				for(int i = 0; i < p-1;i++)
				{
					B[i] = A[i];
				}
				for(int i = p-1; i < p+c-1; i++)
				{
					sort(&A[i], &A[i-(p-1)]);
				}
				for(int i = c; i < c+p-1;i++)
				{
					A[i] = B[i-c];
				}
			}
		}
		cout << A[0] << endl;
	}
	return 0;
}

C++: #include<stdio.h>
int n,r,p,c,i,deck[100],temp[100];

int main(){
  while(1){
    scanf("%d %d",&n,&r);
    if( n==0 && r==0)break;
    for( i = 1; i <=n; i++){
      deck[i] = n - i + 1;
    }
    while(r>0){
      r--;
      scanf("%d %d",&p,&c);
      for( i = 1; i < p; i++){
	temp[i]=deck[i];
      }
      for(i = p ; i < p + c; i++){
	deck[i-p+1] = deck[i];
      }
      for( i = 1; i < p; i++){
	deck[i+c] = temp[i];
      }
    }
    printf("%d\n",deck[1]);
  }
  return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;

const int INF = 1e9 + 7;
const long long LLINF = 1e18;

ll n, r;
int main() {
    while(cin>>n>>r, n!=0 && r!=0){
        ll card[51];
        REP(i, 0, n) card[i]=n-i;

        REP(i, 0, r){
            ll p, c;
            cin>>p>>c;

            ll tmp[51];
            ll idx=0;
            REP(j, 0, c){
                tmp[j]=card[p-1+j];
            }
            REP(j, 0, p-1){
                tmp[j+c]=card[j];
            }
            REP(j, p-1+c, n){
                tmp[j]=card[j];
            }

            REP(j, 0, n){
                card[j]=tmp[j];
            }
        }
        cout<<card[0]<<endl;
    }
    return 0;
}

C++: #include <iostream>
#define MAX 50

using namespace std;

void cut(int[],int,int);

int main(void){
	int p,c;

	for(int n,r;cin >> n >> r,n||r;){
		int card[MAX];
		for(int i=0;i<n;i++)
			card[i]=n-i;

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

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

	return 0;
}

void cut(int card[],int p,int c){
	int tmp[c];

	for(int i=0;i<c;i++)
		tmp[i]=card[p+i];

	for(int i=1;i<=p;i++)
		card[p+c-i]=card[p-i];

	for(int i=0;i<c;i++)
		card[i]=tmp[i];
}

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

using namespace std;

int n[10000]={},r[10000]={};
int p[10000][50] = {};
int c[10000][50] = {};
int i=0;

int d[50]={};
int e[50] = {}; //今の状態
int e2[50] = {};

int main(){
    while(1){
        scanf("%d %d",&n[i],&r[i]);
        if(n[i]== 0 && r[i]== 0){
            break;
        }
        for(int j=0;j<r[i];j++){
            scanf("%d %d",&p[i][j],&c[i][j]);
        }
        i++;
    }
    int times = i;
    for(i=0;i<times;i++){
        //初期化
        int s=0;
        for(int k = n[i]; k>0;k--){
            e[s] = k;
            s++;
        }
        for(int j=0;j<r[i];j++){
            s=0;
            for(int t=p[i][j]-1;t<p[i][j]+c[i][j]-1;t++){
                d[s] = e[t];
                s++;
            }
            for(int t = 0;t < n[i];t++){
                e2[t] = e[t];
            }
            for(int t = 0;t<c[i][j];t++){
                e[t] = d[t];
            }
            s = 0;
            for(int t=c[i][j];t<p[i][j]+c[i][j]-1;t++){
                e[t] = e2[s];
                s++;
            }
            for(int t=0;t<n[i];t++){
                cout<<e[t]<<endl;
            }
            puts("");

        }
        
        cout << e[0] << endl;
    }

    return 0;
}