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 <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h<<":";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

/* template end */

using ll = long long;
using P=std::pair<long long,long long>;

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

  ll n,r;
  
  while(std::cin>>n>>r,n||r){
    std::vector<ll> card(n);
    std::iota(card.rbegin(),card.rend(),1);
    rep(i,0,r){
      ll p,c;
      std::cin>>p>>c;
      std::vector<ll> temp;
      rep(j,p-1,p+c-1)temp.emplace_back(card[j]);
      rep(j,0,p-1)temp.emplace_back(card[j]);
      rep(j,p+c-1,n)temp.emplace_back(card[j]);
      card=temp;
    }

    std::cout<<card[0]<<"\n";
  }

  return 0;
}

C++: #include <iostream>

using namespace std;

int cut(int n, int r, int s[60]){
	int p, c;
	int temp[60] = {0};

	for(int i = 0;i < r;i++){
		cin >> p >> c;
		for(int j = 0;j <= n;j++){
			temp[j] = s[j];
		}
		for(int j = 0;j < p;j++){
			s[n - p - c + j + 2] = temp[n - p + j + 2];
		}
		for(int j = 0;j < c;j++){
			s[n - c + 1 + j] = temp[n - p - c + j + 2];
		}
	}

	return s[n];
}

int main(){
	int n, r, p, c, s[60];
	while(1){
		cin >> n >> r;
		if(n == 0 && r == 0) break;

		for(int i = 0;i <= n;i++){
			s[i] = i;
		}

		int ans = cut(n, r, s);

		cout << ans << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,r,p,c;
  int j;
  int card[50];
  while(1){
    cin>>n>>r;
    if(n==0 && r==0) break;
    j=1;
    for(int i=n-1;i>=0;i--){
      card[i]=j;
      j++;
    }
    for(int i=0;i<r;i++){
      cin>>p>>c;
      rotate(card,card+p-1,card+p+c-1);
      for(int k=0;k<n;k++){
	cout<<card[k]<<" ";
      }
	cout<<endl;
    }
    cout<<card[0]<<endl;
  }
  return 0;
}

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

int main(){
	int n , r;	
	while(cin>>n>>r,n|r){
		vector< pair<int,int> > v(r);
		vector<int> h(n);
		for(int i=0;i<n;++i){
			h[i]=n-i;
		}
		for(int i=0;i<r;++i){
			int p , c;
			cin >> p >> c;
			rotate(h.begin() , h.begin()+p-1 , h.begin()+p-1+c);
		}
		cout << h[0] << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
	int n, r;
	vector<int> card;
	while(true){
		cin >> n >> r;
		if(!n && !r) break;
		card.clear();
		// 1 .. n
		for(int i = 1; i <=n ; i++){
			card.push_back(i);
		}

		for(int i = 0; i < r; i++){
			int p, c;

			cin >> p >> c;
			if(n == c) continue;
			
			vector<int>::iterator it = card.end() - p - c + 1;
			
			// temp
			for(int j = 0; j < c; j++){
				card.push_back(*it);
				it++;
			}
			//erase
			card.erase(it  - c, it);
			
			/*
			it = card.begin();
			while(it != card.end()){
				cout << " " << *it;
				it++;
			}
			cout << endl;
			*/
		}
		cout << card[n-1] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;
int n,r;
int p,c;
vector<int> card;
vector<int> tmp;
int main(){
  while(true){

    cin >> n >> r;
    if(n==0&&r==0)break;
    card.resize(n+2);
    REP(i,n)card[i]=i+1;
    REP(i,r){
      cin >> p >> c;
      for(int j=n-p+1;j<n;j++){
	tmp.push_back(card[j-c]);
	card[j-c] = card[j];
      }
      REP(k,n)cout << card[k] << " ";
	cout << "\n";
	if(p!=1)
	  for(int j=n-c;j<n;j++)
	    card[j] =tmp[j-n+c];
      REP(k,n)cout << card[k] << " ";
      cout << "\n";
      tmp.clear();
    }
    cout << card[n-1] << endl;
    card.clear();

  }

  return 0;
    
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>



using namespace std;



int main()
{
	int n, r, p, c;
	int yama[50], temp[50];
	
	while (cin >> n >> r)
	{
		if (n == 0 && r == 0) break;
		
		//山の初期化
		for (int i=0; i<n; i++)
		{
			yama[i] = n - i;
		}
		
		//カット操作
		for (int i=0; i<r; i++)
		{
			cin >> p >> c;
			for (int j=0; j<p-1; j++)
			{
				temp[c+j] = yama[j];
			}
			for (int j=p-1; j<p+c-1; j++)
			{
				temp[j-p+1] = yama[j];
			}
			for (int j=0; j<p+c-1; j++)
			{
				yama[j] = temp[j];
			}
		}
		
		/*
		//テスト出力
		for (int i=0; i<n; i++)
		{
			cout << yama[i] << endl;
		}
		*/
		
		cout << yama[0] << endl;
	}
	
	return 0;
}