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<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int main(){
  int n, r;
  int a[51];
  int p, c;
  while(cin >> n >> r && n > 0){
    rep(i, n){
      a[i] = n-i;
    }

    rep(i, r){
      cin >> p >> c;
      rotate(a, a+p-1, a+p-1+c);
    }

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



}

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<int>& a) { for (int x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

signed main() {
  while (true) {
    i32 n, r;
    cin >> n >> r;
    if (n == 0) break;
    vector<i32> deck(n);
    iota(RALL(deck), 1);
    REP(_, r) {
      i32 p, c;
      cin >> p >> c;
      rotate(deck.begin(), deck.begin() + p - 1, deck.begin() + p - 1 + c);
    }
    cout << deck[0] << endl;
  }
}

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

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}

signed main() 
{
  int n,r;
  while(cin>>n>>r&&n&&r)
  {
    vi card(n);
    rep(i,n) card[i]=i;
    rep(i,r)
    {
      int p,c; cin>>p>>c;
      rep(k,c)
      {
        rep(j,p-1)
        {
          if(p==1) continue;
          swap(card[n-p-k],card[n-1-j-k]);
        }
      }
    }
    print(card[n-1]+1);
  } 

  return 0;
}

C++: #include<cstdio>
#include<iostream>
#define M 50

int main(void)
{
	int n,r;
	int p,c;
	int i,j,k,l;
	int a[M],temp[M];
	
	for(;;)
	{
		scanf("%d %d",&n,&r);
		if(n==0 && r==0) break;
		
		for(i=0; i<n; i++)
		{
			a[i]=i+1;
			temp[i]=i+1;
		}
		
		for(j=0; j<r; j++)
		{
			scanf("%d %d", &p, &c);
			
			for(i=0; i<n; i++)
			{
				temp[i]=a[i];
			}
			
			for(k=n-p; k<n; k++)
			{
				a[k-c+1]=a[k+1]; //落ちてくる部分の配列
			}

			for(k=0; k<c; k++)
			{
				a[n-c+k]=temp[n-p-c+1+k]; //上に上がる部分の配列
			}

		}
		printf("%d\n",a[n-1]);
	}
	
	
	return 0;
}

C++: /*** ??±????????£????????? ***/

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

int main(){
	int n, r;
	int p, c;
	vector<int> huda, temp;
	vector<int>::iterator itr;
	
	cin >> n >> r;
	for(int i=0; i<n; i++) huda.push_back(i+1);
	
	while(n!=0 && r!=0){
		for(int i=0; i<r; ++i){
			cin >> p >> c;
			
			for(int j=0; j<c; ++j){
				itr = huda.begin()+(n-p-j);
				temp.push_back(*itr);
				huda.erase(itr);
			}
			for(int j=c-1; j>=0; --j){
				itr = temp.begin()+j;
				huda.push_back(*itr);
			}
			
			temp.clear();
		}
		cout << *(huda.begin()+n-1) << endl;
		
		cin >> n;
		cin >> r;
		huda.clear();
		for(int i=0; i<n; i++) huda.push_back(i+1);
	}
	return 0;
}

C++: #include <iostream>

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

int main(void){

	int n, r;		//山の枚数、回数
	int p, c;		//上からの何枚目、枚数
	int n1[50];	//山
	int temp[50];	//一時的に保存しておく
	int ans[50];	//答えを保存しておく
	int j=0;		//答えを格納する時に使う

	while(std::cin >> n >> r, n || r){		//n,rを取得０、０でなければループ

		rep(i,n){
			n1[i] = n-i;						//n1[n] = {n,n-1,n-2,.........,1}
		}

		rep(i,r){

			std::cin >> p >> c;				//p,cを取得
			rep(i, c){
				temp[i] = n1[p-1+i];
			}
			rep(i, p-1){
				n1[p-1-i+c] = n1[p-1-i];
			}

			rep(i,c){
				n1[i] = temp[i];
			}
		}
		std::cout << n1[0] << std::endl;
		//ans[j++] = n1[0];
	}

	/*
	rep(i,j){
		std::cout << ans[i] << std::endl;
	}
	*/
	return 0;
}