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>

#define rep(i, m) for(int i=0; i<m; i++)

int main(void){

	int n, r;		//山の枚数、回数

	while(std::cin >> n >> r, n || r){		//n,rを取得０、０でなければループ

		int n1[51];	//山
		rep(i,n){
			n1[i] = n-i;						//n1[n] = {n,n-1,n-2,.........,1}
		}

		rep(i,r){

			int p, c;		//上からの何枚目、枚数
			int temp[51];	//一時的に保存しておく

			std::cin >> p >> c;				//p,cを取得
			rep(i, c){
				temp[i] = n1[p-1+i];
			}
			rep(i, p-1){
				n1[p-1-i+c] = n1[p-1-i];
			}

			rep(i,c){
				n1[i] = temp[i];
			}
		}
		std::cout << n1[0] << std::endl;
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
    int n,r;

    while (cin>>n>>r && n>0 && r>0){
        int list[50];

        for (int j = 0; j < n; ++j) {
            list[j]=n-j;
        }
        for (int i = 0; i < r; ++i) {
            int p,c;
            int tmp[50];

            cin>>p>>c;
            for (int j = 0; j < c; ++j) {
                tmp[j]=list[p+j-1];
            }
            for (int k = 0; k < p-1; ++k) {
                list[p+c-k-2]=list[p-k-2];
            }
            for (int l = 0; l < c; ++l) {
                list[l]=tmp[l];
            }
        }
        cout<<list[0]<<endl;
    }
    return 0;
}

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

//?±±?????????????????¢??°???????±±???????±±????????°n???p?????????????????????c???                       
void shuffle(vector<int> &yama, int n, int p, int c);


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

  cin >> n;
  cin >> r;

  while(n != 0 && r != 0){
    //?±±??????????????????                                                            
    for(int i = 0, j = n; i < n; i++, j--){
      yama.push_back(j);
    }
    //?????£?????????                                                                
    for (int i = 0; i < r; i++){
      cin >> p;
      cin >> c;
      shuffle(yama, n, p, c);
    }
    //???????????????????¨????                                                          
    v.push_back(yama.front());

    cin >> n;
    cin >> r;
  }
  for(int i = 0; i < v.size(); i++){
    cout << v[i];
  }
  cout << endl;
}

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



int main(){
	queue<int> ans,tmp,tmp2;
	int n,r;
	while(cin>>n>>r,n||r){
		for(int i=0;i<n;i++){
			ans.push(n-i);
		}
		int p,c;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			for(int j=0;j<n;j++){
				if(j<p-1){
					tmp.push(ans.front());ans.pop();
				}else if(j<p+c-1){ 
					tmp2.push(ans.front());ans.pop();
				}else{
					tmp.push(ans.front());ans.pop();
				}
			}
			while(tmp2.empty()!=true){
				ans.push(tmp2.front());tmp2.pop();
			}
			while(tmp.empty()!=true){
				ans.push(tmp.front());tmp.pop();
			}
		}
		cout<<ans.front()<<endl;
		while(ans.empty()!=true){
			//cout<<ans.front();
			ans.pop();
		}
	}
	return 0;
}

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

using namespace std;

vector<int> card;
void shuffle(int p, int c) {
	vector<int> buf(c);

	--p;
	for (int i = 0; i < c; ++i) {
		buf[i] = card[p+i];
	}
	for (int i = p-1; i >= 0; --i) {
		card[c+i] = card[i];
	}
	for (int i = 0; i < c; ++i) {
		card[i] = buf[i];
	}
}
void print() {
	for (int i = 0; i < card.size(); ++i) {
		cout << card[i] << " ";
	}
	cout << endl;
}

int main() {
	int n, r;
	while ( cin >> n >> r, n || r ) {
		card.clear();
		card.resize(n);
		for (int i = 0; i < n; ++i) {
			card[i] = i;
		}
		for (int i = 0; i < r; ++i) {
			int p, c; cin >> p >> c;
			shuffle(p, c);
		}
		cout << n-card[0] << endl;
	}
}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
	int card[50][50]={0};
	int mem[50]={0};
	int n;
	int r;
	int k = 0 ;
	int p,c;
	while(1){
		cin >>n >>r;
		if ((n==0)&&(r==0)) break;
		for(int i =0;i<n;i++){
			card[k][i]=i;
		}	
		for (int j=0;j<r;j++){
			cin >> p >> c ;
			for(int l=0;l<n;l++){
				mem[l]=card[k][l];
			}
			for(int m=0;m<p-1;m++){
				card[k][n-p-c+1+m]=mem[n-p+1+m];
			}
			for(int l=0;l<c;l++){
				card[k][n-c+1+l]=mem[n-p-c+2];
			}
		}
		cout << card[k][n-1] <<endl;
		k++;

	}
	
	return 0;
}

C++: #include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    while (true) {
        int n;
        int r;
        cin >> n >> r;

        if (n == 0 && r == 0) {
            break;
        }

        vector<int> v(static_cast<size_t>(n));
        iota(begin(v), end(v), 1);
        reverse(begin(v), end(v));
        for (int i = 0; i < r; ++i) {
            int p;
            int c;
            cin >> p >> c;
            vector<int> t;
            copy_n(begin(v) + (p - 1), c, back_inserter(t));
            copy_n(begin(v), p, back_inserter(t));
            copy(begin(v) + (p - 1) + c, end(v), back_inserter(t));
            v = t;
        }
        cout << v[0] << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, R;
	cin >> N >> R;
	while (N != 0) {
		vi V(N);
		REP(i, N) {
			V[i] = N-i;
		}
		REP(i, R) {
			int p, c;
			cin >> p >> c;
			vi New(N);
			int ind = 0;
			FOR(j, p - 1,p - 1 + c) {
				New[ind] = V[j];
				ind++;
			}
			REP(j, p-1) {
				New[ind] = V[j];
				ind++;
			}
			FOR(j,p-1+c,N) {
				New[ind] = V[j];
				ind++;
			}
			V = New;
		}
		cout << V[0] << endl;
		cin >> N >> R;
	}
	return 0;
}

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

int main(){
		
	int n,r,p,c ;
	int x,y;
	int a[51]={},b[51]={},card[51]={};
	
	while(1){
		cin >> n >> r ;
		if( n==0 && r==0 ) break;
		
		for( int i=1 ; i<=n ; i++ ) card[i] = n-i+1 ;
		
		for( int i=0 ; i<r ; i++ ){
			cin >> p >> c ;
			
			for( x=1 ; x<p ; x++ ) a[x] = card[x] ;
			for( y=1 ; y<=c ; y++ ) b[y] = card[x+y-1] ;
			
			swap(a,b);
			
			for( x=1 ; x<=c ; x++ ) card[x] = a[x] ;
			for( y=1 ; y<p ; y++ ) card[x+y-1] = b[y] ;
		}
		
		cout << card[1] << endl ;
	}
	
return 0;
}