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>

using namespace std;

int main(){

   while(1){

      int n, r;
      cin>> n>> r;
      if(n==0&&r==0) break;
      int a[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 b[c];
         for(int j=p-1; j<p+c-1; j++){
            b[j-(p-1)]=a[j];
         }
         for(int j=p-1; j>0; j--){
            a[j]=a[j-1];
         }
         for(int j=0; j<c; j++){
            a[j]=b[j];
         }
      }

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

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

void Shuffle(int n, int r){
	int c,p;
	int Deck[50];
	int tmp[50];
	//?±±?????????
	for(int i = 0;i < n;i++){
		Deck[i] = n - i;
	}
	//?????£?????????
	for(int i = 0; i < r; i++){
		cin >> p >> c;
		p--; //??????????????????????????????

		//p??????c???????????????????????£??????
		for(int j = 0; j < c; j++){
			tmp[j] = Deck[j + p];
		}
		//???????????????
		for(int j = p-1; j >= 0; j--){
			Deck[j+c] = Deck[j];
		}
		//?????£?????????????????????????????????
		for(int j = 0; j < c; j++){
			Deck[j] = tmp[j];
		}
	}
	cout << Deck[0] << endl;
}

int main(void){
	int n; //?±±???????????°
	int r; //???????????????????????°
	while(1){
		cin >> n >> r;
		if(n == 0 && r == 0){
			return 0;
		}
		Shuffle(n,r);
	}
	return 0;
}

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

typedef long long LL;
#define rep(i ,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define all(v) (v).begin(),(v).end()
#define arycpy(ary1,ary2,N) memcpy(ary2,ary1,sizeof(int)*N) //ary1:???????????? ary2:????????????
typedef vector<int> vi;


int main(){
	while (1){
		int n, r;
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		int *num = new int[n];
		for (int i = 0; i < n; i++){
			num[i] = n-i;
		}
		for (int i = 0; i < r; i++){
			int p, c; cin >> p >> c;
			int *ary = new int[n];
			rep(i, n) ary[i] = 0;
			for (int j = 0; j < c; j++){
				ary[j] = num[p - 1 + j];
			}

			for (int j = c; j <c+p-1; j++){
				ary[j] = num[j - c];
				//cout << j << " : " << ary[j] << " : " << num[j - c] << endl;
			} 

			//rep(i, n) cout << ary[i] << " ";
			//cout << endl;

			for (int j = p; j < n; j++){
				ary[j] = num[j];
			}
			arycpy(ary, num, n);
			//rep(i, n) cout << num[i] << " ";
			//cout << endl;
		}
		cout << num[0] << endl;
	}
	return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n,r,p,c;
	while(cin >> n >> r, n+r){
		int huda[50];
		for(int i=0; i<n; i++){
			huda[i]	= n-i;
		}
		for(int i=0; i<r; i++){
			cin >> p >> c;
			int tmp[50];
			for(int j=0; j<c; j++){
				tmp[j] = huda[p+j-1];
			}
			for(int j=p-2; j>=0; j--){
				huda[j+1] = huda[j];
			}
			for(int j=0; j<c; j++){
				huda[j]=tmp[j];	
			}
		}
		cout << huda[0] << "\n";
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  int a[51]={};
  int st[51]={};
  int n,r;
  int p,c;
  while(1){
    //in
    cin >> n >> r;
    if(n==0&&r==0)break;
    for(int i=0;i<n;i++){
      a[i]=n-i;
    }
    for(int i=0;i<r;i++){
      cin >> p >>c; 
      for(int j=0;j<n;j++){
	st[j]=a[j];
      }
      for(int j=0;j<c;j++){
	a[j]=st[p+j-1];
      }
      for(int j=0;j<p;j++){
	a[j+c]=st[j];
      }
    }
    cout << a[0] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main(void){
	int n, r;
	while(cin >> n >> r, n | r){
		int card[n];
		card[0] = n;
		for(int i = 1; i < n; i++)card[i] = card[i-1]-1;
		rep(i,r){
			int p, c;
			cin >> p >> c;
			int abv[p];
			for(int j = 0; j < p; j++){
				abv[j] = card[j];
			}
			for(int j = 0; j < c; j++){
				card[j] = card[p+j];
			}
			for(int j = 0; j < p; j++){
				card[c+j] = abv[j];
			}
		}
		cout << card[0]+1 << endl;
	}

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

C++: #include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int  card[60];
int tmp[60];
int p,c;

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

	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define endl '\n'
const int INF = (1 << 30);
using namespace std;
typedef long long int ll;

bool solve(){
    int n,r;
    cin >> n >> r;
    if(!n&&!r) return false;
    int deck[n], deck_[n];
    REP(i,n){ deck[i] = deck_[i] = n-i; }
    REP(ki,r){
        int p, c;
        cin >> p >> c;
        p--;
        REP(ci,c){
            deck_[ci] = deck[p+ci];
        }
        REP(i,n-c){
            deck_[c+i] = deck[i];
        }
        REP(i,n-p-c){
            deck_[p+c+i] = deck[p+c+i];
        }
        REP(i,n){
            deck[i] = deck_[i];
        }
    }
    cout << deck[0] << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    while(solve());
}

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

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) c.begin(),c.end()
static const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
static const int MOD = (int)(1e9 + 7);

signed main() {
	for (int n, r; cin >> n >> r&&n;) {
		vector<int> v(n); rep(i, 0, n) { v[i] = n - i; }
		rep(i, 0, r) {
			vector<int> tmp = v;
			int p, c; cin >> p >> c;
			rep(j, 0, p - 1) {
				tmp[j + c] = v[j];
			}
			rep(j, 0, c) {
				tmp[j] = v[j + p - 1];
			}
			swap(tmp, v);
		}
		cout << v[0] << endl;
	}
	return 0;
}