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>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <array>

using namespace std;

int A[51];
int n,m,p,c;

int main(){
    while(true){
        cin >> n >> m;
        if(n+m == 0)break;
        for(int i = 0;i < n;i++)A[i] = n - i;
        for(int i = 0;i < m;i++){
            cin >> p >> c;
            rotate(A,A+p-1,A+p+c-1);
//            for(int k = 0;k < n;k++){
//                cout << A[k] << " ";
//            }
//            cout << endl;
        }
        cout << A[0] << endl;
    }
}

C++: #include <cstdio>

int n, r;
int card[55], tmp[55];

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

C++: using namespace std;

int main(){
    int n,r,p,c,a[50];

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

        for(int i=0;i<r;i++){
            cin >> p >> c;
            rotate(a,a+p-1,a+p+c-1);
        }
    cout << a[0] << endl;
    }

    return 0;

}

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