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

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cmath>

using namespace std;

#define all(c) ((c).begin()),((c).end())
#define debug(c) cerr<<"> "<<#c<<" = "<<(c)<<endl;
#define iter(c) __typeof((c).begin())
#define tr(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	for(int n, r; cin >> n >> r, (n | r) != 0; ) {
		vi cards(n);
		rep(i, n) cards[i] = n - i;
		rep(i, r) {
			int p, c; cin >> p >> c;
			rotate(cards.begin(), cards.begin() + p - 1, cards.begin() + p + c - 1);
		}
		cout << cards.front() << endl;
	}
	
	return 0;
}

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

int main() {
	while (1) {
		int n;//ÔDÌ
		int r;//VbtÌñ
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		int cards[n];//J[h
		for (int i = 0; i < n; i++) {
			cards[i] = n - i;
		}
		//rñVbt·é
		for (int i = 0; i < r; i++) {
			int p, c;//pÚ©çc
			cin >> p >> c;
			int tmp[c];//ð·ÌêL¯p
			//tmpÉpÚ©çcði[
			for (int j = p - 1; j < p + c - 1; j++) {
				tmp[j - p + 1] = cards[j];
			}
			//tmpÉi[µ½ªðã«µÄlßé
			for (int j = p - 2; j >= 0; j--) {
				cards[j + c] = cards[j];
			}
			//tmpðãÉß·
			for (int j = 0; j < c; j++) {
				cards[j] = tmp[j];
			}
		}
		cout << cards[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-1] = yama[p-1-k-1];
			}
			rep(l,c){
				yama[l] = tmp[l];
			}
		}
		std::cout << yama[0] << std::endl;
	}

	return 0;
}

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

#define PI 4*atan(1)
#define INF 1e8

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

int main(){
  int n, r;
  while(cin >> n >> r, n || r){
    vector<int> card(n);
    for(int i = 0; i < n; i++)card[i] = i + 1;
    int p, c;
    for(int i = 0; i < r; i++){
      cin >> p >> c;
      p--;
      for(int j = p; j < p + c; j++){
        int tmp;
        tmp = card[card.size() - p - c];
        card.erase(card.begin() + card.size() - p - c);
        card.push_back(tmp);
      }
    }
    cout << card[n - 1] << endl;
  }
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n, r;
  while (cin >> n >> r, n) {
    vi v(n);
    rep(i, n) v[i] = n - i;
    rep(i, r) {
      int p, c;
      cin >> p >> c;
      vi w;
      w.reserve(c);
      for (int j = p - 1; j < p - 1 + c; j++) w.pb(v[j]);
      for (int j = p - 2; j >= 0; j--) v[j + c] = v[j];
      rep(j, w.size()) v[j] = w[j];
    }
    cout << v[0] << endl;
  }
}