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 <string>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

typedef long long LL;
#define rep(i ,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define all(v) (v).begin(),(v).end()
#define arycpy(ary1,ary2,N) memcpy(ary2,ary1,sizeof(int)*N) //ary1:???????????? ary2:????????????
typedef vector<int> vi;


int main(){
	while (1){
		int n, r;
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		int *num = new int[n];
		for (int i = 0; i < n; i++){
			num[i] = n-i;
		}
		for (int i = 0; i < r; i++){
			int p, c; cin >> p >> c;
			int *ary = new int[n];
			rep(i, n) ary[i] = 0;
			for (int j = 0; j < c; j++){
				ary[j] = num[p - 1 + j];
			}

			for (int j = c; j <c+p-1; j++){
				ary[j] = num[j - c];
				//cout << j << " : " << ary[j] << " : " << num[j - c] << endl;
			} 

			//rep(i, n) cout << ary[i] << " ";
			//cout << endl;

			for (int j = p; j < n; j++){
				ary[j] = num[j];
			}
			arycpy(ary, num, n);
			//rep(i, n) cout << num[i] << " ";
			//cout << endl;
		}
		cout << num[0] << endl;
	}
	return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n,r,p,c;
	while(cin >> n >> r, n+r){
		int huda[50];
		for(int i=0; i<n; i++){
			huda[i]	= n-i;
		}
		for(int i=0; i<r; i++){
			cin >> p >> c;
			int tmp[50];
			for(int j=0; j<c; j++){
				tmp[j] = huda[p+j-1];
			}
			for(int j=p-2; j>=0; j--){
				huda[j+1] = huda[j];
			}
			for(int j=0; j<c; j++){
				huda[j]=tmp[j];	
			}
		}
		cout << huda[0] << "\n";
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  int a[51]={};
  int st[51]={};
  int n,r;
  int p,c;
  while(1){
    //in
    cin >> n >> r;
    if(n==0&&r==0)break;
    for(int i=0;i<n;i++){
      a[i]=n-i;
    }
    for(int i=0;i<r;i++){
      cin >> p >>c; 
      for(int j=0;j<n;j++){
	st[j]=a[j];
      }
      for(int j=0;j<c;j++){
	a[j]=st[p+j-1];
      }
      for(int j=0;j<p;j++){
	a[j+c]=st[j];
      }
    }
    cout << a[0] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main(void){
	int n, r;
	while(cin >> n >> r, n | r){
		int card[n];
		card[0] = n;
		for(int i = 1; i < n; i++)card[i] = card[i-1]-1;
		rep(i,r){
			int p, c;
			cin >> p >> c;
			int abv[p];
			for(int j = 0; j < p; j++){
				abv[j] = card[j];
			}
			for(int j = 0; j < c; j++){
				card[j] = card[p+j];
			}
			for(int j = 0; j < p; j++){
				card[c+j] = abv[j];
			}
		}
		cout << card[0]+1 << endl;
	}

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

C++: #include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int  card[60];
int tmp[60];
int p,c;

int main(){
	while(1){
		int n,r;
		scanf("%d %d",&n,&r);
		if(n + r == 0) break;
		for(int i = 0;i < n;i++){
			card[n-i] = i+1;
		}
		for(int i = 0;i < r;i++){
			scanf("%d %d",&p,&c);
			for(int j = 1;j <= c;j++){
				tmp[j] = card[j + p - 1];
			}
			for(int j = p-1;j > 0;j--){
				card[j+c] = card[j];
			}
			for(int j = 1;j <= c;j++){
				card[j] = tmp[j];
			}
		}
		printf("%d\n",card[1]);

	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define endl '\n'
const int INF = (1 << 30);
using namespace std;
typedef long long int ll;

bool solve(){
    int n,r;
    cin >> n >> r;
    if(!n&&!r) return false;
    int deck[n], deck_[n];
    REP(i,n){ deck[i] = deck_[i] = n-i; }
    REP(ki,r){
        int p, c;
        cin >> p >> c;
        p--;
        REP(ci,c){
            deck_[ci] = deck[p+ci];
        }
        REP(i,n-c){
            deck_[c+i] = deck[i];
        }
        REP(i,n-p-c){
            deck_[p+c+i] = deck[p+c+i];
        }
        REP(i,n){
            deck[i] = deck_[i];
        }
    }
    cout << deck[0] << endl;
    return true;
}

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

    while(solve());
}

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

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) c.begin(),c.end()
static const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
static const int MOD = (int)(1e9 + 7);

signed main() {
	for (int n, r; cin >> n >> r&&n;) {
		vector<int> v(n); rep(i, 0, n) { v[i] = n - i; }
		rep(i, 0, r) {
			vector<int> tmp = v;
			int p, c; cin >> p >> c;
			rep(j, 0, p - 1) {
				tmp[j + c] = v[j];
			}
			rep(j, 0, c) {
				tmp[j] = v[j + p - 1];
			}
			swap(tmp, v);
		}
		cout << v[0] << endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>

void shuffle(int card[50],int p,int c){
	int d[50],i;
	memcpy(d,card.50 * sizeof(int));
		for(i = 0;i < c;i++){
		d[i] = card[p - 1 + i];
	}
		for(i = 0; i < p - 1;i++){
			d[c + i] = card[i];
		}
	memcpy(card,d,50 * sizeof(int));
}


int main(void){
	int n,r,p,c,i,card[50];
	
	while(1){
		scanf("%d %d",&n,&r);
			if(n == 0 && r == 0) break;
		for(i = 0; i < n;i++){
			card[i] = i;
		}
		
		for(i = 0;i < n; i++){
			 scanf("%d %d",&p,&c);
			 shuffle(card,p,c);
			}
		printf("%d\n",(n + 1 - card[0]));
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	while (true) {
		int n, r;
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		int a[50];
		rep(i, n) a[i] = n - i;
		rep(j, r) {
			vector<int> v;
			int p, c;
			cin >> p >> c;
			REP(i, p - 1, p + c - 2) {
				v.push_back(a[i]);
			}
			rep(i, n) {
				if (p - 1 <= i && i <= p + c - 2) continue;
				v.push_back(a[i]);
			}
			//rep(i, n) {
			//	cout << v[i] << " ";
			//}
			//cout << endl;
			rep(i, n) a[i] = v[i];
		}
		cout << a[0] << endl;
	}

    return 0;
}