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>
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++;
			}
		}
		cout << card[0] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;

int main() {
    int n,r;
    while(cin >> n >> r) {
        if(n == 0 && r == 0) break;
        vector<int> v(n);
        rep(i,n) v[i] = n-i;
        
        rep(i,r) {
            int p,c;
            cin >> p >> c;

            vector<int> ret;
            REP(j,p-1,p-1+c) {
                ret.push_back(v[j]);
            }

            rep(j,p-1) {
                ret.push_back(v[j]);
            }

            REP(j,p-1+c,n) {
                ret.push_back(v[j]);
            }

            rep(j,n) v[j] = ret[j];
        }

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

C++: #include<iostream>

#define rep(i,n) for(int i=0; i<n; i++)

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

	while(std::cin >> n >> r && (n || r)){
		int c,p;
		rep(i,n){
			yama[i] = n-i;
		}
		rep(i,r){
			std::cin >> p >> c;
			rep(j,c){
				tmp[j] = yama[p-1+j];
			}
			rep(k,p-1){
				yama[p-1+c-k] = yama[p-1-k];
			}
			rep(l,c){
				yama[l] = tmp[l];
			}
		}
		std::cout << yama[0] << std::endl;
	}

	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cctype>

#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

typedef pair<int ,int> P;

int main()
{
    int N,R;
    while(cin >> N >> R && N != 0 && R != 0)
    {
        int card[N];
        rep(i,N+1) { card[i] = N - i; };
        rep(i,R)
        {
            int p,c;
            cin >> p >> c;

            int tmp_card[N];
            rep(j,N) { tmp_card[j] = 0; }
            rep(j,c){ tmp_card[j] = card[p - 1 + j]; } 
            rep(j,p-1) { tmp_card[j + c] = card[j]; }
            rep(j,c + p-1) { card[j] = tmp_card[j]; }
        }
        cout << card[0] << endl;
    }
}

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

int main(){
	int n, r;
	while( cin >> n >> r, n||r ){
		vector<int> card(n+1);
		for( int i=1; i<=n; i++ ){
			card[i] = n-i+1;
		}
		while(r--){
			int p, c;
			cin >> p >> c;
			vector<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+1] = tmp[i];
			}
		}
		cout << card[1] << endl;
	}
	return 0;
}

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

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

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

//#define int int64_t

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)

#define all(c) begin(c), end(c)
#define maxup(ans, x) (ans = (ans < x ? x : ans))
#define minup(ans, x) (ans = (ans > x ? x : ans))

#define breakif(cond) if(cond) break; else

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

signed main() {
	int n;
	while (cin >> n && n) {
		int r; cin >> r;
		V cards(n);
		rep(i, n) cards[i] = n - i;
		rep(_, r) {
			int p, c; cin >> p >> c;
			p--;
			rep(i, c) {
				for (int idx = p + i; idx - 1 >= i; idx--) {
					swap(cards[idx - 1], cards[idx]);
				}
			}
		}
		cout << cards[0] << endl;
	}
}

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

using namespace std;

void shuffle(int *cards,int p, int c){
	int *mt1 = new int[p-1];
	for(int i=0;i<p-1;i++){
		mt1[i] = cards[i];
	}	
	int *mt2 = new int[c];
	for(int i=0;i<c;i++){
		mt2[i] = cards[p-1+i];
	}
	for(int i=0;i<c;i++){
		cards[i] = mt2[i];
	}
	for(int i=0;i<p-1;i++){
		cards[c+i] = mt1[i];
	}
	delete[] mt1;
	delete[] mt2;
}

int main(){
	int n,r;//カードの枚数,シャッフルの回数
	while(true){
		cin >> n >> r;
		if(n==0 && r==0){
			break;
		}
		int *cards = new int[n];
		for(int i=0;i<n;i++){
			cards[i] = n-i;
		}
		for(int i=0;i<r;i++){
			int p,c;//上からpの場所からc個
			cin >> p >> c;
			shuffle(cards,p,c);
		}
		int result = cards[0];
		cout << result << endl;
		delete[] cards;
	}
	
	return 0;
}

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

#define rep(i,n)  for(int i=0; i<n; i++)

int main(){
  int n, r;
  while(true){
    cin>>n>>r;
    if(n==0 && r==0)break;
    int ans=n;
    stack<pair<int, int> > st;
    rep(i,r){
      int p, c;
      cin>>p>>c;
      st.push(pair<int, int>(p, c));
    }
    while(!st.empty()){
      pair<int, int> tmp=st.top(); st.pop();
      if(ans>(n-tmp.second)){ans-=(tmp.first-1);}//オレンジ
      else if(ans>(n-tmp.first-tmp.second+1)){ans+=tmp.second;}//ブルー
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

int main(){
  
  int n, r, p, c;
  int card[60], tmp[60];

  while(cin>>n>>r, n){
    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<c;j++) tmp[j]=card[p-1+j];
      for(int j=0;j<p;j++) card[p-1+c-j-1]=card[p-1-j-1];
      for(int j=0;j<c;j++) card[j]=tmp[j];
    }
    cout<<card[0]<<endl;
  }
  
  return 0;
}