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 <bits/stdc++.h>
using namespace std;

int main() {
    int N, R;
    while (cin >> N >> R, N || R) {
        vector<int> v(N);
        for (int i = 0; i < N; i++) {
            v[i] = i+1;
        }

        while (R--) {
            int p, c;
            cin >> p >> c;
            auto w = v;
            for (int i = 0; i < p-1; i++) {
                w[N - p - c + i + 1] = v[N - p + i + 1];
            }

            for (int i = 0; i < c; i++) {
                w[N - c + i] = v[N - p - c + i + 1];
            }

            v = w;
        }

        cout << v[N-1] << endl;
    }

    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(s) (s).begin(),(s).end()
#define ITE(c) typeof((c).begin())

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

using namespace std;

int main(){
	int n, r, p, c;
	vector<int> ls;
	while(cin>>n>>r&&n||r){
		ls.clear();
		for(int i=n;i>0;i--){
			ls.push_back(i);
		}
			
		rep(j,r){
			cin>>p>>c;
			vector<int> tmp;
			for(int i=p-1;i<p+c-1;i++){
				tmp.pb(ls.at(i));
			}
			ls.erase(ls.begin()+p-1,ls.begin()+p+c-1);
			EACH(i,ls){
				tmp.pb((*i));
			}
			ls.clear();
			EACH(i,tmp){
				ls.push_back((*i));
			}
		}
		cout<<ls.at(0)<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
	int card[50][50]={0};
	int mem[50]={0};
	int n;
	int r;
	int k = 0 ;
	int p,c;
	while(1){
		cin >>n >>r;
		if ((n==0)&&(r==0)) break;
		for(int i =0;i<n;i++){
			card[k][i]=i+1;
		}	
		for (int j=0;j<r;j++){
			cin >> p >> c ;
			for(int l=0;l<n;l++){
				mem[l]=card[k][l];
			}
			for(int m=0;m<p-1;m++){
				card[k][n-p-c+1+m]=mem[n-p+1+m];
			}
			for(int o=0;o<c;o++){
				card[k][n-c+o]=mem[n-p-c+1+o];
			}
		}
		cout << card[k][n-1] <<endl;
		k++;

	}
	
	return 0;
}

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

int main()
{
  int n,r;
  int p,c;
  
  while(cin >> n >> r,n||r){

    vector<int> card(n,0);
    for(int i=0;i < n;i++){
      card[i]=i+1;
    }
    reverse(card.begin(),card.end());
    
    for(int i=0;i < r;i++){
      cin >> p >> c;
      rotate(card.begin(),card.begin()+p-1,card.begin()+p-1+c);
      
      // rotate(a,b,c):= [a,b)と[b,c)を入れ替え
    }
    cout << *card.begin() << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
    while (true) {
        int n, r, a[50];

        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++) {
            int p, c;
            cin >> p >> c;
            rotate(a, a+p-1, a+p+c-1);
        }

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

    return 0;
}

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

int n, r;
int head, val[51], nxt[51];

int main() {
	while (cin >> n >> r, n) {
		head = 0;
		for (int i=0; i<n; ++i) {
			val[i] = n-i;
			nxt[i] = i+1;
		}
		
		for (int i=0; i<r; ++i) {
			int p, c;
			cin >> p >> c;
			if (p == 1) continue;
			
			int it_p = head;
			while (p>2) it_p = nxt[it_p], --p;
			
			int it_c = it_p;
			while (c) it_c = nxt[it_c], --c;
			
			int tmp = head;
			head = nxt[it_p];
			nxt[it_p] = nxt[it_c];
			nxt[it_c] = tmp;
		}
		
		cout << val[head] << endl;
	}
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,r;
  while(cin >> n >> r && n && r){
    vary(ll,v,n,0);
    rep(i,n){
      v[i] = n-i;
    }
    ll p,c;
    rep(i,r){
      cin >> p >> c;
      auto v2 = v;
      REP(j,p-1,p+c-1){
        v2[j-p+1] = v[j];
        v[j] = -1;
      }
      for(ll j = 0; j < n;){
        if(v[j] == -1){
          ++j;
        }
        else{
          v2[c] = v[j];
          ++c;
          ++j;
        }
      }
      v = v2;
    }
    cout << v[0]<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

typedef vector <int> VI;
typedef vector <VI> VVI;
typedef vector <string> VS;
typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, LL> PIL;
typedef vector <PIL> VPIL;


#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define sort(c) sort((c).begin(),(c).end())

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

#define MAX_INT 2147483647

int main(){
	int n, r, p, c;
	VI deck, tmp_deck;
	while (1){
		cin >> n >> r;  
		if (!(n and r)) break;
		deck.resize(n);
		rep(i,n) deck[i] = n - i;
		rep(i,r){
			cin >> p >> c;
			tmp_deck.resize(p-1);
			rep(j,p-1) tmp_deck[j] = deck[j];
			rep(j,c) deck[j] = deck[j+p-1];
			rep(j,p-1) deck[j+c] = tmp_deck[j];
		}
		cout << deck[0] << endl;
	}
	return 0;
}