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 <bits/stdc++.h>
using namespace std;
int main(void){
    int n,r,p,c;
    while(cin>>n>>r,n){
        vector<int> v(n,0);
        iota(v.rbegin(),v.rend(),1);
        for(int i=0;i<r;i++){
            cin>>p>>c;
            vector<int> t(c,0);
            for(int j=0;j<c;j++){
                t[j]=v[j+p-1];
            }
            for(int j=p-1;j>0;j--){
                v[c+j-1]=v[j-1];
            }
            for(int j=0;j<c;j++){
                v[j]=t[j];
            }
        }
        cout<<v[0]<<endl;
    }
}

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

using namespace std;

int main(){
	int n, r, p, c;
	int *before, *after;
	while(cin >> n >> r && n){
		before = new int[n];
		after = new int[n];
		for(int i=0; i<n; i++) before[i]=n-i, after[i]=n-i;
		for(int i=0; i<r; i++){
			cin >> p >> c;
			for(int i=0; i<c; i++) after[i] = before[p-1+i];
			for(int i=0; i<p-1; i++) after[c+i] = before[i];
			for(int i=0; i<n; i++) before[i]=after[i];
		}
		cout << after[0] << endl;
		delete[] after;
		delete[] before;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, r, p, c;
V v;

int main(){
	while (cin >> n >> r&&n + r){
		REP(i, n){
			v.push_back(n - i);
		}
		REP(i, r){
			cin >> p >> c;
			V t;
			REP(i, c){
				t.push_back(v[p - 1 + i]);
			}
			REP(i, p - 1){
				t.push_back(v[i]);
			}
			FOR(i, p - 1 + c, n){
				t.push_back(v[i]);
			}
			v = t;
		}
		cout << v[0] << endl;
		v.clear();
	}
}

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

int main()
{
	int n, r, card[51], temp[51];
	while (cin >> n >> r, n || r){

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

		//入力と操作
		for (int i = 0; i < r; i++){
			int p, c;
			cin >> p >> c;

			//tempにコピー
			for (int i = 0; i < p - 1 + c; i++)
				temp[i] = card[i];

			//上からc個
			for (int i = 0; i < c; i++){
				card[i] = temp[p - 1 + i];
			}

			//上からp個
			for (int i = 0; i < p - 1; i++){
				card[c + i] = temp[i];
			}
		}

		//出力
		cout << card[0]<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

constexpr int MAX = 50;

int main (int argc, char *argv[]) {
    int n, r, p, c;
    vector<int> h;
    int i, j;
    
    // input
    while (cin>>n>>r, n||r) {
        // init
        for (i = 0, j = 1; i < n; ++i, ++j) {
            h.push_back(j);
        }

        // solve
        for (i = 0; i < r; ++i) {
            // cout<<"-----init------"<<endl;
            // for (int i = n-1; i > -1; --i) {
            //     cout<<i<<":"<<h[i]<<endl;
            // }

            cin>>p>>c;

            int p_ = n - p;
            int c_ = p_ - (c - 1);

            // copy
            vector<int> tmp;
            for (int i = 0; i < c; ++i) {
                tmp.push_back(h[c_]);
                c_++;
            }

            // cout<<"---tmp---"<<endl;
            // for (int i = c-1; i >= 0; --i) {
            //     cout<<tmp[i]<<endl;
            // }

            // erase
            c_ = p_ - (c - 1);
            h.erase(h.begin() + c_, h.begin() + c_ + c);

            // cout<<"-----erase------"<<endl;
            // // for (int i = n-1; i > -1; --i) {
            // //     cout<<h[i]<<endl;
            // // }
            // for (auto e : h) {
            //     cout<<e<<endl;
            // }
        
            // copy
            for (int i = 0; i < c; ++i) {
                h.push_back(tmp[i]);
            }

            tmp.clear();
        }

        // cout<<"-----init------"<<endl;
        // for (int i = n-1; i > -1; --i) {
        //     cout<<h[i]<<endl;
        // }

        // cout<<"---ans---"<<endl;
        cout<<h[n-1]<<endl;
        
        // clear
        h.clear();
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
using namespace std;

int n,r,p,c;
int before[50],after[50],tmp[50];

void init(){
	for(int i=0;i<50;i++)
		after[i]=tmp[i]=0;
}

bool input(){	
	int i;
	cin>>n;
	cin>>r;
	for(i=0;i<n;i++)
		before[i]=n-i;	
	return 1;
}

void Shuffle(int b[], int a[], int t[]){
	int j;
	for(j=0;j<c;j++){
			a[j]=b[p-1+j];
			t[j]=b[p-1+j];
		}
		for(j=0;j<p;j++){
			a[c+j]=b[j];
			t[c+j]=b[j];
		}
		for(j=0;j<n;j++)
			b[j]=t[j];
}


int solve(){
	for(int i=0;i<r;i++){
		cin>>p>>c;
		Shuffle(before,after,tmp);
	}
	return after[0];
}


int main(){
	n=r=1;
  while((n!=0)&&(r!=0)){
	init(),input();
	cout<<solve()<<endl;
  }
  return 0;
}

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

int main(){
	int n, r, p, c, temp[200], tempp[200] = {}, tempc[200] = {}, i;
	
	while(1){
		cin>>n>>r;
		
		if(n == 0 && r == 0) break;
		
		for(i = 1; i <= n; i++) temp[i] = n-i+1;
		//for(i = 1; i < n; i++) cout<<temp[i]<<endl;
		for(int j = 0; j < r; j++){
			cin>>p>>c;
			for(i = 1; i < p; i++) tempp[i] = temp[i];
			for(i = 1; i <= c; i++) tempc[i] = temp[i+p-1];
			for(i = 1; i <= c; i++) temp[i] = tempc[i];
			for(i = 1; i < p; i++) temp[i+c] = tempp[i];
		}
	//	for(i = 1; i < n; i++) cout<<temp[i]<<" "<<tempc[i]<<" "<<tempp[i]<<endl;
		cout<<temp[1]<<endl;
		
	}
	
	
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int n, r, p, c;
	int i,j;
	while (cin >> n >> r) {
		if (n == 0 && r == 0)break;
		int sta[50]; int copsta[50];
		for (i = 0; i < n; i++) {
			sta[i] = n-i;
		}
		for (i = 0; i < r; i++) {
			for (j = 0; j < n; j++) {
				copsta[j] = sta[j];
			}
			cin >> p >> c;
			for (j = 0; j < p + c - 1; j++) {
				if (j < c) {
					sta[j] = copsta[j + p-1];
				}
				else sta[j] = copsta[j - c];
			}
		}
		cout << sta[0] << endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

const int MAX = 50;

int data[MAX];
int in,num;
int copyA[MAX];

void change(int p, int c){

  for(int i = p; i < p+c; i++) data[i-p] = copyA[i];
  for(int i = 0; i < p; i++) data[i+c] = copyA[i]; 
}
void make(){
  for(int i = 0; i < in; i++) data[i] = i;
}
void copy_1(){
  for(int i = 0; i < in; i++) copyA[i] = data[i];
}

int main(){

  while(cin >> in >> num && in+num){
    make();
    for(int i = 0; i < num; i++){
      int p,c;
      cin >> p >> c;
      copy_1();
      change(p-1,c);
    }
    cout << in - data[0] << endl;
  }
  return 0;
}