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<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	int n,i,j,r,p,c,sum;
	string s;
	vector<int> v,w,x;
	while(1){
		cin>>n>>r;
		if(n==0&&r==0)break;
		
		v.clear();
		w.clear();
		x.clear();
		rep(i,n) v.push_back(i+1);
		rep(j,r){
			
			cin>>p>>c;
			for(i=0;i<n;i++){
				if(i>=n-(p+c-1)&&i<n-(p+c-1)+c) x.push_back(v[i]);
				else w.push_back(v[i]);
			}
			rep(i,x.size()) w.push_back(x[i]);
			v=w;
		//	cout<<v[v.size()-1]<<endl;
			w.clear();
			x.clear();
		//	cout<<"aaaa"<<v.size()<<endl;
		//	rep(i,v.size())cout<<v[i]<<" ";
		//	cout<<endl;
		}
		cout<<v[v.size()-1]<<endl;
	}/*
	5 2
	3 1
	3 1
	v1 2 4 5 3
	if(i>=2&&i<3)
	w1 2 4 5 3
	x3
	*/
	
	
	
//////////////////////////////////////////////////////
return 0;}

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

vector<int> deck;

void swap(int n,int p,int c){
  int tmp[p-1];
  for(int i=0;i<p-1;i++)
    tmp[i]=deck[n-1-i];
  for(int i=0;i<c;i++){
    deck[n-1-i]=deck[n-p-i];
  }
  for(int i=0;i<p-1;i++)
    deck[n-1-c-i]=tmp[i];

}

int main(){
  int n,r,c,p;
  while(cin>>n>>r,n){
      deck.clear();
    for(int i=0;i<n;i++)
      deck.push_back(i+1);
    for(int i=0;i<r;i++){
      cin>>p>>c;
      swap(n,p,c);
    }
    // for(int i=0;i<deck.size();i++)
    //cout<<deck[deck.size() - 1 - i]<<endl;
    //cout<<endl;
    cout<<deck[deck.size()-1]<<endl;
  }
  return 0;
}

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

using namespace std;

int32_t main()
{
  while(true){
    uint32_t n, r;
    cin >> n >> r;
    if(n == 0) break;

    vector<uint32_t> cards(51, 0);
    for(int32_t i = n-1, j = 1;  i >= 0; i--, j++){
      cards[i] = j;
    }

    for(uint32_t i = 0; i < r; i ++){
      uint32_t p, c;
      cin >> p >> c;
      vector<uint32_t> cs;
      for(uint32_t i = p - 1; i < p - 1 + c; i++){
        cs.push_back(cards[i]);
      }
      for(uint32_t i = 0; i < p - 1; i++){
        cs.push_back(cards[i]);
      }
      for(uint32_t i = p - 1 + c; i < n; i++){
        cs.push_back(cards[i]);
      }

      for(uint32_t i= 0; i < n; i++){
        // cout << cs[i] << " ";
        cards[i] = cs[i];
      }
      // cout << endl;
    }

    cout << cards[0] << endl;
  }
  return 0;
}

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

using namespace std;

void solve()
{
	int n, r;
	while(cin >> n >> r, n , r)
	{
		int p, c;
		stack<int> data;
		stack<int> buf1;
		stack<int> buf2;
		for(int i = 1; i <= n; ++i)
		{
			data.push(i);
		}
		while(r--)
		{
			cin >> p >> c;
			for(int i = 0; i < p - 1; ++i)
			{
				buf1.push(data.top());
				data.pop();
			}
			for(int i = 0; i < c; ++i)
			{
				buf2.push(data.top());
				data.pop();
			}
			int size1 = buf1.size();
			int size2 = buf2.size();
			for(int i = 0; i < size1; ++i)
			{
				data.push(buf1.top());
				buf1.pop();
			}
			for(int i = 0; i < size2; ++i)
			{
				data.push(buf2.top());
				buf2.pop();
			}
		}
		cout << data.top() << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){

  while(1){
    int n,r;
    cin>>n >>r;
    if(n==0&&r==0)  break;
    int cards[n-1];
    REP(i,n){
      cards[i] = (n-i);
    }
    int help[100]={0};
    int p[100];
    int c[100];
    REP(i,r){
      cin>>p[i]>>c[i];
      REP(j,c[i]){
	help[c[i]-j-1] = cards[p[i]+c[i]-2-j];
      }
      for(int j=0;(p[i]-1-j)>=0;j++){
	if((p[i]-1-j)<0) break;
	cards[p[i]+c[i]-2-j] = cards[p[i]-2-j];
      }
      REP(j,c[i]){
	cards[j]=help[j];
      }
    }
    cout << cards[0] << endl;
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int input(char s[]);

int main() {
	int cnt,ans[10000],n, r,brk=0,p,c,x[50],xs[50];
	for (int i = 0; i < 50; i++)
		x[i] = xs[i] = i;

	//while (1) {
	for (cnt=0; cnt<10000; cnt++) {
		scanf("%d %d", &n, &r);
		if (n == 0 && r == 0)
			brk = 1;
		if (brk == 1)
			break;
		for (int i = 0; i < r&&brk == 0; i++) {
			scanf("%d %d", &p, &c);
			for (int j = 0; j < c; j++)
				x[j] = xs[j + p - 1];
			for (int j = c; j < c + p - 1; j++)
				x[j] = xs[j - c];
			for (int j = 0; j < n; j++)
				xs[j] = x[j];}
			ans[cnt] = n - x[0];
	}
	for (int i = 0; i < cnt; i++)
		printf("ans:%d\n", ans[i]);
	return 0;
}

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

main()
{
  while(1){
    int n,r; cin >> n >> r;
    if(n == 0) break;
    vi a(n);
    rep(i,n) a[i] = n-i;
    rep(i,r){
      int p,c; cin >> p >> c;
      vi C(c);
      FOR(j,p-1,p+c-1) C[j-p+1] = a[j];
      ROF(j,p-1,0) a[j+c] = a[j];
      rep(j,c) a[j] = C[j];
    }
    cout << a[0] << endl;
  }      
}

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

int main(){

	int n, r;
	while(cin >> n >> r, n|r){
		vector<int> now(100), next(100);
		for(int i=0; i<n; i++){
			now[n-1-i] = i+1;
		}
		for(int i=0; i<r; i++){
			int p, c; cin >> p >> c;
			for(int j=0; j<n; j++){	
				if(j<c){
					next[j] = now[p-1+j];
				}else if(j<c+p){
					next[j] = now[j-c];
				}else{
					next[j] = now[j];
				}
			}
			now = next;
		}
		cout << now[0] << endl;
	}

	return 0;
}