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<iomanip>
#include<cstdio>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define REEP(i, N) for(ll i = N - 1; i >= 0; --i)
#define FOR(i,m,n) for(ll i = m; i < n; ++i)
#define RFOR(i,m,n) for(ll i = n - 1; i >= m; --i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define PB push_back
#define KIRIAGE(a, b) a += (b - a % b) % b // a ??? b ????????°????????§?¢???????
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;} // a / b ??\??????????°???´??°
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
int main(void) {
    while(true) {
        int n, r;
        cin>>n>>r;
        vector<ll> card(n);
        REP(i, n) {
            card[i] = n - i;
        }
        if(n==0&&r==0) return 0;
        REP(i, r) {
            int p, c;
            cin>>p>>c;
            vector<ll> hoge(p - 1);
            REP(i, p - 1) hoge[i] = card[i];
            REP(i, c) card[i] = card[p - 1 + i];
            REP(i, p - 1) card[c + i] = hoge[i];
        }
        cout<<card[0]<<endl;
    }
}

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

int main() {
  int n, r;

  while(cin >> n >> r, n+r) {
    vector<int> card(n);
    for(int i = 0; i < n; i++) card[i] = n-i;
    for(int i = 0; i < r; i++) {
      int p, c;
      cin >> p >> c;
      vector<int> tmp(p-1);
      for(int j = 0; j < p-1; j++) tmp[j] = card[j];
      for(int j = 0; j < c; j++) card[j] = card[j+p-1];
      for(int j = 0; j < p-1; j++) card[j+c] = tmp[j];
    }
    cout << card[0] << endl;
  }  
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n,r;
	while(cin>>n>>r,r){
		int cards[60],i;
		for(i=0;i<60;i++)cards[i]=i;
		for(i=0;i<r;i++){
			int a,b;
			cin>>a>>b;
			a--;
			int j;
			int c[60];
			for(j=0;j<60;j++){
				if(j<b){
					c[j]=cards[a+j];
				}else if(j<a+b){
					c[j]=cards[j-b];
				}else{
					c[j]=j;
				}
			}
			for(j=0;j<60;j++){
				cards[j]=c[j];
//cout<<cards[j]<<endl;
			}
//cout<<endl;
		}
		cout<<n-cards[0]<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
int main(){
  int n,r,p,c,i,j,k,l,nh[51],s[51];
  while(1){
    scanf("%d%d",&n,&r);
    if(n==0&&r==0) break;
 
    for(i=n;i>=1;i--){
      nh[n-i+1]=i;
    }
  
    for(i=0;i<r;i++){
      scanf("%d%d",&p,&c);
      for(j=p;j<=p+c-1;j++){
        s[j]=nh[j];
      }
    l=0;
      for(j=1;j<=c;j++){
    for(k=p-1+l;k>=1+l;k--){
          nh[k+1]=nh[k];
    }
        l++;
      }
     
      for(j=p;j<=p+c-1;j++){
        nh[j-p+1]=s[j];
      }
    }
 
    printf("%d\n",nh[1]);
  }
    return 0;
}

C++: #include <iostream>

using namespace std;

void cut(int[],int,int);

int main(void){
	int p,c;

	for(int n,r;cin >> n >> r,n||r;){
		int card[n];
		for(int i=0;i<n;i++)
			card[i]=n-i;

		for(int i=0;i<r;i++){
			cin >> p >> c;
			if(p!=1)
				cut(card,p,c);
		}

		cout << card[0] << endl;
	}

	return 0;
}

void cut(int card[],int p,int c){
	int tmp[c];

	for(int i=0;i<c;i++)
		tmp[i]=card[p-1+i];

	for(int i=1;i<=p;i++)
		card[p+c-i]=card[p-i];

	for(int i=0;i<c;i++)
		card[i]=tmp[i];
}

C++: #include <iostream>
#include <cstdio>
#include <queue>
#define INF 1e+18
#define int long long
using namespace std;

signed main(){
	int n,r;
	while(cin >> n >> r,n){
		int card[50];
		for(int i = 0;i < n;i++) card[i] = n - i;
		queue<int> que;
		for(int i = 0;i < r;i++){
			int a,b;
			cin >> a >> b;
			for(int j = 0;j < a - 1;j++) que.push(card[j]);
			for(int j = a - 1;j < a + b - 1;j++) card[j - a + 1] = card[j];
			for(int j = b;j < a + b - 1;j++){
				 card[j] = que.front();
				 que.pop();
			}
		}
		cout << card[0] << 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 =l ;j <=p;j++){
      Card[j] =temp[m++];
    }
  }
  cout <<Card[1]<<endl;
  }
  return 0;
}

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

int n, r, p, c, d[50], e[50];

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

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

using namespace std;

int main( void ){
	vector< int > result;
	deque< int > card;
	while( true ){
		int n, r;
		cin >> n >> r;
		if( n == 0 && r == 0 )
			break;
		for( int i = 1; i < n + 1; i++ ){
			card.push_front( i );
		}
		for( int i = 0; i < r; i++ ){
			int p, c;
			cin >> p >> c;
			for( auto itr = card.begin(); itr != card.end(); ++itr ){
				if( ( *itr ) =< p ){
					int temp = ( *itr );
					card.erase( itr );
					card.push_front( temp );
				}
			}
		}

		result.push_back( card.front() );
			
	}

	for( auto itr = result.begin(); itr != result.end(); ++itr ){
		cout << ( *itr ) << endl;
	}

	return 0;
}