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 <stdio.h>
int n, r, p, c, d[50], e[50];
int main() {
	while (true) {
		scanf("%d%d", &n, &r);
		if (n == 0 && r == 0) break;
		for (int i = 0; i < n; i++) d[i] = n - i;
		for (int i = 0; i < r; i++) {
			scanf("%d%d", &p, &c);
			for (int j = 0; j < c; j++) {
				e[j] = d[j + p];
			}
			for (int j = c; j < p + c; j++) {
				e[j] = d[j - c];
			}
			for (int j = 0; j < p + c; j++) {
				d[j] = e[j];
			}
		}
		printf("%d\n", d[0]);
	}
	return 0;
}

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

int main(){
	int n,r,p,c;

	while(true){
		vector<int> cards;
		int check[50]={0};
		cin >> n >> r;
		if(n == 0 && r == 0){
			break;
		}

		
		for(int i=n;i!=0;i--){
			cards.push_back(i);
		}
		vector<int> buf;
		for(int i=0;i<r;i++){
			cin >> p >> c;
			for(int j=0;j<c;j++){
				buf.push_back(cards[p+j-1]);
				check[p+j-1] = 1;
			}
			for(int j=0;j<n;j++){
				if(check[j] == 0){
					buf.push_back(cards[j]);
				}else{
					check[j] = 0;
				}
			}
			cards.clear();
			for(int j=0;j<n;j++){
				cards.push_back(buf[j]);
			}
			buf.clear();
		}

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

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

int main(){
	int n, r, p, c;
	int card[50], tmp;

	
	while(cin >> n >> r){
		if(n ==0 && r == 0)
			break;

		for(int i=0; i<n; i++){
			card[i] = n-i;
		}

		for(int i=0; i<r; i++){
			cin >> p >> c;

			for(int j=0; j<c; j++){
				tmp = card[p-1+j];
				for(int k=p-2+j; k>=j; k--){
					card[k+1] = card[k];
				}
				card[j] = tmp;
			}
		}
	cout << card[0]  << "\n";
	}
	return 0;
}

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

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

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

#define itn long long
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)(n);i>=0;--i)
#define debug(x) cout << #x << "=" << (x) << endl;
const ll MOD=1e9+7;

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end

void solve(){
  while(1){
    int n,r;
    cin>>n>>r;
    if(!(n|r))return;
    vector<int> A(n);
    rep(i,n)
      A[n-1-i]=i+1;
    rep(i,r){
      int p,c;
      cin>>p>>c;--p;
      vector<int> newA(n,0);
      for(int j=p;j<p+c;j++)
        newA[j-p]=A[j];
      for(int j=0;j<p;j++)
        newA[j+c]=A[j];
      rep(j,n)
        if(!newA[j])
          newA[j]=A[j];
      A=newA;
    }
    cout<<A[0]<<endl;
  }
}
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  solve();
  return 0;
}