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++: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

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

  int n, r;
  while (cin >> n >> r) {
    if (n == 0 && r == 0) break;
    vector<P> num(n);
    rep(i, n) {
      num[i].first = i + 1;
      num[i].second = n - i;
    }

    rep(i, r) {
      int p, c;
      cin >> p >> c;
      int tmp = 1;
      rep(i, p + c - 1) {
        if (i < p - 1) {
          num[i].first += c;
        } else {
          num[i].first = tmp;
          tmp++;
        }
      }
      sort(all(num));
    }

    cout << num[0].second << "\n";
  }

  return 0;
}

C++: #include <iostream>
using namespace std;
 
int n, r, p, c;
int cards[64];
 
void init() {
    for(int i = 0; i < n; i++)
        cards[i] = n - i;
}
 
bool input() {
    cin >> n >> r;
    if(!n && !r)
        return false;
    return true;
}
 
void shuffle() {
    int tmp[64];
    
    // c 個分の要素をtmpに格納
    for(int i = 0; i < c; i++)
        tmp[i] = cards[p - 1 + i];
    // p-1 個分の要素を c 個分ずらす
    for(int i = 0; i < p - 1; i++)
        cards[p - 2 - i + c] = cards[p - 2 - i];
    // 先頭に c 個分の要素をつめる
    for(int i = 0; i < c; i++)
        cards[i] = tmp[i];
}
 
int solve() {
    for(int i = 0; i < r; i++) {
        cin >> p >> c;
        shuffle();
        
        for(int j = 0; j < n; j++)
            cout << cards[j] << " ";
        cout << endl;
    }
    return cards[0];
}
 
int main() {
    while(input()) {
        init();
        cout << solve() << endl;
    }
    return 0;
}

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

int main(){
    int n,r,p,c;
    vector<int> cards;

    while(cin >> n >> r, n&&r){
        cards.clear();
        for(int i = 0; i < n; i++){
            cards.push_back(n - 1);
        }
        while(r--){
            cin >> p >> c;
            vector<int> cpCards = cards;
            int pos = 0;
            for(int i = p - 1; i < p - 1 + c; i++){
                cards[pos] = cpCards[i];
                pos++;
            }
            for(int i = 0; i < p - 1; i++){
                cards[pos] = cpCards[i];
                pos++;
            }
        }
        cout << cards.front() << endl;
    } 
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int main(){
  int n, r;
  while(scanf("%d%d", &n, &r) && n && r){
    vector<int>a(n);
    rep(i, n) a[i] = n-i;
    int p, c;
    //    rep(i, n) printf("%d ", a[i]); puts("");
    while(r--){
      scanf("%d%d", &p, &c);p--;
      vector<int>tmp(c);
      REP(i, p, p + c) tmp[i-p] = a[i];
      for(int i = p; i > 0; --i) a[i] = a[i-c];
      rep(i, c) a[i] = tmp[i];
      //      rep(i, n) printf("%d ", a[i]); puts("");
      //      rep(i, c) printf("%d ", tmp[i]); puts("");
    }
    //    rep(i, n) printf("%d ", a[i]); puts("");
    printf("%d\n", a[0]);
  }
  return 0;
}

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

int main() {
	int n, r;
	while(cin >> n >> r, n || r) {
		vector<int> v(n);
		iota(v.rbegin(), v.rend(), 1);
		
		for(int i = 0; i < r; ++i) {
			int p, c;
			cin >> p >> c;
			p--;
			auto temp = v;
			for(int j = 0; j < c; ++j) {
				temp[j] = v[p + j];
			}
			
			for(int j = 0; j < p; ++j) {
				temp[c + j] = v[j];
			}
			
			swap(v, temp);
		}
		cout << v[0] << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,r;
  while(cin>>n>>r,n+r!=0){
    queue<int> yama;
    queue<int> x;
    queue<int> y;
    for(int i=n;i>=1;i--)
      yama.push(i);
    for(int i=0;i<r;i++){
      int p,c;
      cin>>p>>c;
      for(int i=0;i<p-1;i++){
	x.push(yama.front());
	yama.pop();
      }
      for(int i=0;i<c;i++){
	y.push(yama.front());
	yama.pop();
      }
      while(!x.empty()){
	yama.push(x.front());
	x.pop();
      }
      while(!y.empty()){
	yama.push(y.front());
	y.pop();
      }
    }
    cout<<yama.front()<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <map>
#include <deque>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n,r;
	
	while(cin >> n >> r , n){
		deque<int> card(n);
		rep(i,n)card[n-i-1]=i+1;

		rep(i,r){
			int p,c;
			cin >> p >> c;
			deque<int> t(c);
			rep(j,c)t[j] = card[p-1+j];
			rep(j,c)card.erase( remove(card.begin(),card.end(),t[c-1-j]),card.end() );
			rep(j,c)card.push_front(t[c-1-j]);
		}
		cout << card[0] << endl;
	}
}

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

using namespace std;

int main()
{
	int n, m, s, t;
	
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0){
			break;
		}
		queue<int> que, qu1, qu2, qu3;
		
		for(int i = n; i >= 1; i--){
			que.push(i);
		}
		while(m--){
			cin >> s >> t;
			for(int i = 0; i < s-1; i++){
				qu1.push(que.front());
				que.pop();
			}
			for(int i = 0; i < t; i++){
				qu2.push(que.front());
				que.pop();
			}
			while(!que.empty()){
				qu3.push(que.front());
				que.pop();
			}
			while(!qu2.empty()){
				que.push(qu2.front());
				qu2.pop();
			}
			while(!qu1.empty()){
				que.push(qu1.front());
				qu1.pop();
			}
			while(!qu3.empty()){
				que.push(qu3.front());
				qu3.pop();
			}
		}
		cout << que.front() << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,r;
	while(1){
		cin>>n>>r;
		if(n==0 && r==0)break;
		string s="";
		for(int i=n;i>=1;i--){
			s+=(char)(i+'0');
		}
		cout<<s<<endl;
		rep(i,r){
			int p,c;
			cin>>p>>c;
			string sub=s.substr(0,p-1);
			s.insert(p,sub);
			s.erase(0,p-1);
		}
		cout<<s[0]<<endl;
	}
	return 0;
}