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 <vector>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    for(int n,r;cin>>n>>r,n;){
        vi cur(n);
        rep(i,n) cur[i] = n-i;
        rep(i,r){
            int p,c; cin >> p >> c;
            p--;
            vi next = cur;
            rep(i,c+p){
                next[i] = cur[(i+p)%(c+p)];
            }
            swap(cur,next);
        }
        cout << cur[0] << endl;
    }
}

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

int main(){
	while (true){
		int n, r,a[50];
		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++){
			int p, c, b[50];
			cin >> p >> c;
			for (int j = 0; j < p-1; j++){
				b[j] = a[j];
			}
			for (int j = 0; j < c; j++){
				a[j] = a[p + j-1];
			}
			for (int j = 0; j < p-1; j++){
				a[c + j] = b[j];
			}
			cout << a[0] << endl;
		}

		cout << a[0] << endl;
	}
	return 0;
}

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

using namespace std;

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,j,n) for(int i = j; i < n; i++)


int main(){
	while(1){
		int n,r;
		cin >> n >> r;
		if(n == 0 && r == 0){
			break;
		}

		vector<int> m(n);
		rep(i,n){
			m[i] = n - i;
		}

		rep(i,r){
			int p, c;
			cin >> p >> c;
			vector<int> w;

			REP(i,p-1,p-1+c){
				w.push_back(m[i]);
			}

			REP(i,0,p-1){
				w.push_back(m[i]);
			}

			REP(i,p-1+c,n){
				w.push_back(m[i]);
			}
			m = w;
		}
		cout << m[0] << endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

   while(1){

      int n, r;
      cin>> n>> r;
      if(n==0&&r==0) break;
      int a[n];
      for(int i=0; i<n; i++) a[i]=n-i;
      for(int i=0; i<r; i++){
         int p, c;
         cin>> p>> c;
         int b[c];
         for(int j=p-1; j<p+c-1; j++){
            b[j-(p-1)]=a[j];
         }
         for(int j=p+c-1; j>c-1; j--){
            a[j]=a[j-c];
         }
         for(int j=0; j<c; j++){
            a[j]=b[j];
         }
      }

      cout<< a[0]<< endl;
   }
   return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int N, R, p, c;
    while (cin >> N >> R && N) {
        vector <int> A(N,0);
        for (int i = 0; i < N; ++i) A[i] = N - i;
        for (int i = 0; i < R; ++i) {
            cin >> p >> c;
            rotate(A.begin(), A.begin()+p-1,A.begin()+c+p-1);
        }
        cout << A[0] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#define rep(i,n) for(int i = 1 ; i <= n ; i++)

using namespace std;

int main()
{
  while(true){
    int n,r;
    cin >> n >> r;
    if(n == 0 && r == 0) break;
    
    vector<int> card;
    rep(i, n){
      card.push_back(i);
    }
    int p,c;
    for( ; r > 0 ; r--){
      cin >> p >> c;

      p = n - p - c + 1;
      for( ; c > 0 ; c--){
	card.push_back(card[p]);
	card.erase(card.begin() + p);
      }
    }
    cout << card.back() << '\n';
  }
}

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

using namespace std;

int top_search(int,int,int,int *);
int main(){
	int n,r,c,p;
	int cnt=0;
	int top[50];
	while(1){
		cin>>n>>r;
		if(n==0&&r==0)
			break;
		int hanahuda[50];
		for (int i = n-1; i>=0 ; i--)
			hanahuda[i]=n-i;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			top[cnt]=top_search(n,p,c,hanahuda);
		}
		cnt++;
	}
	for(int m=0;m<cnt;m++)
		cout<<top[m]<<endl;
	return 0;
}
int top_search(int n,int p,int c,int *hanahuda){
	int cnt=0;
	for(int k=p-1;k<p+c-1;k++){
		int nokori=hanahuda[k];
		for(int l=p-2;l>=0;l--){
			hanahuda[l+1]=hanahuda[l];
		}
		hanahuda[cnt]=nokori;
		cnt++;
	}

	return *hanahuda;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<fstream>

#define SIZE 50

using namespace std;

int main(){
	int kard[SIZE]	= {0};
	int n,k,p,c;

	while(cin>>n>>k,n){
		for(int i=0;i<n ;i++){
			kard[i]	=n-i;
		}
		for(int i=0; i<k; i++){
			cin>>p>>c;
			rotate(kard,kard+p-1,kard+p-1+c);
		}
		cout<<kard[0]<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

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

        vector<int> vec(n);
        rep(i, n) vec[i] = n-i;
        rep(i, r) {
            int p, c; cin >> p >> c;
            p--;
            int loc = 0;
            rep(j, c) {
                int num = vec[p];
                vec.erase(vec.begin()+p);
                vec.insert(vec.begin()+loc, num);
                p++;
                loc++;
            }
        }
        cout << vec.front() << endl;
    }
}

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

int n, r, p, c;
int h[51];

int main() {
  while(cin>>n>>r,n|r) {
    for(int i=0;i<n;++i) {
      h[i+1] = i+1;
    }
    for(int i=0;i<r;++i) {
      cin>>p>>c;
      rotate(h+1, h+p, h+p+c);
    }
    cout << h[1] <<endl;
  }
  return 0;
}

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

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

void initStatus(vector<int> &v) {
    int size = v.size();
    for (int i = 0; i < size; i ++) {
        v[i] = size - i;
    }
}

vector<int> change(vector<int> &v, int n, int p, int c) {
    vector<int> v1(p - 1);
    vector<int> v2(c);
    vector<int> v3(n - (p - 1) - c);

    int count_v1 = 0;
    int count_v2 = 0;
    int count_v3 = 0;

    for (int i = 0; i < n; i ++) {
        if (i < p - 1) {
           v1[count_v1] = v[i]; 
           count_v1 ++;
        } else if (i > p + c - 2) {
            v3[count_v3] = v[i];
            count_v3 ++;
        } else {
            v2[count_v2] = v[i];
            count_v2 ++;
        }
    }
        std::copy(v1.begin(),v1.end(),std::back_inserter(v2));
        std::copy(v3.begin(),v3.end(),std::back_inserter(v2));
    return v2;
}

int shuffle(vector<int> &v, int n, int r) {
    int p;
    int c;
    for (int i = 0; i < r; i ++) {
        cin >> p >> c; 
        v = change(v, n, p, c);
    }
}

int main() {
    int n;
    int r;
    cin >> n >> r; 
    while (n != 0 && r != 0) {
        vector<int> v(n);
        initStatus(v);
        shuffle(v, n, r);
        cout << v[0] << endl;
        cin >> n >> r; 
    }
    return 0;
}