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>
using namespace std;
int main() {
	int n, r,card[50],cut[50],p,c;
	while (cin >> n >> r && n&&r) {
		for (int i = 0; i < n; ++i) card[i] = i + 1;
		for (int i = 0; i < r; ++i) {
			cin >> p >> c;
			for (int j = 0; j < c; ++j) cut[j] = card[n - p - j];
			for (int j = 1; j < p; ++j) card[n - p -c+ j] = card[n - p + j];
			for (int j = 0; j < c; ++j) card[n-j-1] = cut[j];
		}
		cout << card[n-1] << endl;
	}
	return 0;
}

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

const int N = 50;
int d[N], t[N];

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

C++: #include <iostream>

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

int main(void){

	int n, r;		//山の枚数、回数
	int p, c;		//上からの何枚目、枚数
	int n1[50];	//山
	int temp[50];	//一時的に保存しておく
	int ans[50];	//答えを保存しておく
	int j=0;		//答えを格納する時に使う

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

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

		rep(i,r){

			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];
			}
		}
		ans[j++] = n1[0];
	}

	rep(i,j){
		std::cout << ans[i] << std::endl;
	}

	return 0;
}

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

int main(int argc, char const* argv[])
{
  while (true) {
    int n, r;
    std::cin >> n >> r;
    if (n == 0 && r == 0) {
      break;
    }
    std::vector<int> deck(n);
    for (int i = 0; i < n; ++i) {
      deck[i] = n - i;
    }
    for (int i = 0; i < r; ++i) {
      int p, c;
      std::cin >> p >> c;
      std::vector<int> tmp(c);
      for (int j = 0; j < c; ++j) {
        int x = deck[p - 1];
        deck.erase(deck.begin() + p - 1);
        tmp[j] = x;
      }
      deck.insert(deck.begin(), tmp.begin(), tmp.end());
    }
    std::cout << deck[0] << std::endl;
  }
  return 0;
}

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

int main(){
    int n, r;
    while(cin >> n >> r, n+r){
        int arr[n];
        for(int i = 0; i < n; i++)  arr[i] = n-i;
        int p, c;
        for(int i = 0; i < r; i++){
            cin >> p >> c;
            int next[n], pos = 0;
            for(int j = p-1; j < p-1+c; j++)  next[pos++] = arr[j];
            for(int j = 0; j < p-1; j++)    next[pos++] = arr[j];
            for(int j = p-1+c; j < n; j++)    next[pos++] = arr[j];
            copy(next, next+n, arr);
        }
        cout << arr[0] << endl;
    }
    return 0;
}

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

int main(){
	int n,r,p,c;
	while(cin >> n >> r, n+r){
		int huda[50], tmp[50];
		for(int i=0; i<n; i++){
			huda[i]	= n-i;
			tmp[i] = n-1;
		}
		for(int i=0; i<r; i++){
			cin >> p >> c;
			for(int j=0; j < p+c-1; j++){
				if(j<p-1){
					tmp[j+c] = huda[j];
				}else{
					tmp[j-p+1] = huda[j];
				}
			}
			for(int j=0; j<n; j++){
				huda[j] = tmp[j];	
			}
		}
		cout << huda[0] << "\n";
	}
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(c) (c).begin(),(c).end()
int main(){
	while(true){
		int n,r,a[50]={},b[50]={};
		cin >> n >> r;
		if(n==0) break;
		rep(i,n) a[i]=n-i;
		rep(i,r){
			int p,c;
			cin >> p >> c;
			rotate(a,a+p-1,a+p+c-1);
		}
		cout << a[0] << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


int main(void){
	int ans[1000],cnt=0;
	while(1){
		int n,r;
		cin>>n>>r;
		if(n==0)break;
		int p[50],c[50];
		irep(i,r)cin>>p[i]>>c[i];//?????????????????????
		int pos=0;
		rep(i,r){
			if(pos<c[i]){
				pos+=p[i]-1;
			}else if(pos<c[i]+p[i]-1){
				pos-=c[i];
			}
		}
		ans[cnt]=n-pos;
		cnt++;
	}
	rep(i,cnt)cout<<ans[i]<<endl;
	return 0;
}

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

using namespace std;

int main(){
  int n, r;
  vector<int> card;
  card.reserve(100);
  while(true){
    cin >> n >> r;
    if(!n && !r) break;
    card.clear();
    // 1 .. n
    for(int i = 1; i <=n ; i++){
      card.push_back(i);
    }

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

      cin >> p >> c;
      if(n == c) continue;
      
      vector<int>::iterator it = card.end() - p - c + 1;
      
      // temp
      for(int j = 0; j < c; j++){
        card.push_back(*it);
        it++;
      }
      //erase
      card.erase(it  - c, it);
      
      /*
        it = card.begin();
        while(it != card.end()){
        cout << " " << *it;
        it++;
        }
        cout << endl;
      */
    }
    cout << card[n-1] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <list>
#include <cstdlib>

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	int n,r;

	cin >> n;
	cin >> r;

	while (n != 0 || r != 0) {
		std::list<int> lst;
		int now = 1;

		for (int i = 0; i < n; i++) {
			lst.push_back(i+1);
		}

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

			for (std::list<int>::iterator itr = lst.begin(); itr != lst.end();) {
				if (index >  n-(p-1)-c && index < n-(p-2) && r != n){
					lst.push_back(*itr);
					itr = lst.erase(itr);
				}else{
					itr++;
				}	
				index++;
			}
		}
		for (std::list<int>::iterator itr = lst.begin(); itr != lst.end(); ++itr) {
			if (now == n) {
				cout << *itr << "\n";
			}
			now++;
		}
		cin >> n;
		cin >> r;
	}	
	return 0;
}

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

int N, R, p, c;

void show(vector<int> v){
    for (int i = 0; i < N; i++){
        cout << v[i] << " ";
    }
    cout << endl;
}

int main(){
    while (cin >> N >> R && N){
        vector<int> card(N);
        for (int i = 0; i < N; i++){
            card[i] = N - i;
        }
        //cout << "初期入力"<< endl;
        //show(card);

        for (int i = 0; i < R; i++){
            cin >> p >> c;
            rotate(card.begin(), card.begin()+p-1, card.begin()+p+c-1);
            //cout << i+1 << "回目のrotate" << endl;
            //show(card);
        }
        cout << card[0] << endl;
    }
}

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

int m[4][4];

int main(){
	int i,j;
	int n,r,p,c;
	int f[51],buf[51];
	while(cin >> n >> r,(n||r)){
		for(i=1;i<=n;i++){
			f[i]=-i+n+1;
		}
		while(r--){
			cin >> p >> c;
			for(i=1;i<p;i++) buf[i]=f[i];	//buf
			for(i=1;i<=c;i++) f[i]=f[i+p-1];
			for(i=1;i<p;i++) f[i+c]=buf[i];
		}
		cout << f[1] << endl;
	}
	return 0;
}