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 ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   int n, r;
   while (1) {
      // 初期化
      cin >> n >> r;
      vec<int> v(n);
      rep (i, n) { v[i] = n-i; }
      if (n == 0 && r == 0) return 0;

      // 実体
      while (r--) {
         int p, c;
         cin >> p >> c;
         vec<int> next;
         p--;
         repp (i, p, p+c) {
            next.push_back(v[i]);
         }
         rep (i, n) {
            if (i >= p && i < p+c) continue;
            next.push_back(v[i]);
         }

         v = next;
      }
      cout << v[0] << endl;
   }

   return 0;
}

C++: #include <bits/stdc++.h>

#define var auto
#define long long long
#define ll long
#define Max std::max
#define Min std::min
#define Abs std::abs

void Solve();

using namespace std;

int main() {
    while (true) {
        Solve();
    }
}

void Solve() {
    int n, r;
    cin >> n >> r;
    if (n == 0 && r == 0) exit(0);
    var pile = new vector<int>(n);
    iota(pile->begin(), pile->end(), 1);
    reverse(pile->begin(), pile->end());
    for (int i = 0; i < r; ++i) {
        var newPile = new vector<int>();
        int p, c;
        cin >> p >> c;
        for (int j = p - 1; j < p + c - 1; ++j) {
            newPile->push_back((*pile)[j]);
        }
        for (int j = 0; j < p - 1; ++j) {
            newPile->push_back((*pile)[j]);
        }
        for (int j = p + c - 1; j < n; ++j) {
            newPile->push_back((*pile)[j]);
        }
        pile = newPile;
    }
    cout << (*pile)[0] << endl;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, r;
	while (1) {
		cin >> n >> r;
		if (!n) break;
		vector<int> card(n);
		REP(i, n) {
			card[i] = n - i;
		}
		REP(i, r) {
			int p, c;
			cin >> p >> c;
			int *tmp = new int[c];
			REP(j, c) tmp[j] = card[p - 1 + j];
			RREP(j,p-1 ) card[j+c] = card[j];
			REP(j, c) card[j] = tmp[j];
		}
		cout << card[0] << endl;


	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

int main() {
	
	int n,r,p,c;
	
	while(1){
	cin>>n>>r;
	if(n==0&&r==0)return 0;
	int ca[50],d[50];
	for(int i=0;i<n;i++){ca[i]=n-i;d[i]=0;}
	
	for(int i=0;i<r;i++){
		cin>>p>>c;
		for(int j=0;j<p-1;j++)d[j]=ca[j];
		for(int j=0;j<c;j++)ca[j]=ca[p-1+j];
		for(int j=0;j<p-1;j++)ca[c+j]=d[j];
	}
	cout<<ca[0]<<endl;
	}
}

C++: #include<bits/stdc++.h>

using namespace std;

int main(){
	
	while(1){
		
		int n,count;
		
		cin >> n >> count;
		
		if(n==0 && count==0)
			return 0;
		
		int d[n];
		
		for(int i=0;i<n;i++)
			d[i] = n-i;
		
		for(int i=0;i<count;i++){
			int p,c;
			
			cin >> p >> c;
			
			int t[n];
			
			int j;
			for(j=0;j<c;j++){
				t[j]=d[p-1+j];
			}
			for(;j<c+p-1;j++){
				t[j]=d[j-c];
			}
			for(;j<n;j++){
				t[j]=d[j];
			}
			for(j=0;j<n;j++){
				d[j]=t[j];
			}
		}
		cout << d[0] <<endl;
		
	}
	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::flush;
		//ans[j++] = n1[0];
	}

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

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int Card[60];
int temp[60];
int main()
{
  int n,r;
  while(cin >>n>>r,n||r){
  int k = n;
  for(int i = 1; i <=n;i++){
    Card[i] =k--;
  }
  int p,c;
  for(int i = 0;i <r;i++){
    cin>>p>>c;
    int l = 1;
    int m = 1;
    for(int j = 1; j <=p+c-1;j++){
      temp[j] = Card[j];
    }for(int j = p;j <=p+c-1;j++){
      Card[l++] =Card[j];
    }for(int j =0 ;j <=p-1;j++){
      Card[l+j] =temp[m++];
    }
  }
  cout <<Card[1]<<endl;
  }
  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;
}