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 hanafuda[51], tmp[51];

int main()
{
    int n,c,p,r;
    while(cin >> n >> r && n && r) {
        for(int i = 0; i < n; i++)
            hanafuda[i] = i + 1;
        
        for(int i = 0; i < r; i++) {
            cin >> p >> c;
            
            for(int j = 0; j < c; j++) 
                tmp[c - 1 - j] = hanafuda[n - p - j];
            
            for(int j = n - p + 1; j < n; j++)
                hanafuda[j - c] = hanafuda[j];

            for(int j = 0; j < c; j++)
                hanafuda[n - c + j] = tmp[j];

        }
        cout << hanafuda[n - 1] << endl;
    }
}

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

//constant
const int inf=1<<28;

//variable
int n,r;
int p,c;


int main(){
    while(cin>>n>>r,r){
        deque<int> pile;
        for(int i=0; i<n; i++){
            pile.push_front(i+1);
        }
        for(int i=0; i<r; i++){
            cin>>p>>c;
            deque<int> temp;
            for(int i=0; i<c; i++){
                temp.push_front(*(pile.begin()+p-1));
                pile.erase(pile.begin()+p-1);
            }
            while(!temp.empty()){
                pile.push_front(temp.front());
                temp.pop_front();
            }
        }
        /*cout<<endl;
        for(auto it=pile.begin(); it!=pile.end(); it++){
            cout<<*it<<endl;
        }
        cout<<endl;*/
        cout<<pile.front()<<endl;
    }

    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cstdio>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 50;

int main()
{
    int n, r, c, p;
    int before[MAXN];
    int after[MAXN];

    while(cin >> n >> r && (n || r))
    {
        REP(n) { before[i] = after[i] = n - i;}
        
        rep(k,r)
        {
            cin >> p >> c;
            
            for(int i = 0;i < c; i++)
                after[i] = before[i + p - 1];

            for(int i = 0;i < p - 1; i++)
                after[i + c] = before[i];

            REP(MAXN) before[i] = after[i];
        }
        cout << after[0] << endl;

    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int index[51];
int main(){
  int n,r;
  while(cin>>n>>r,n+r){
    for(int i=0;i<n;++i) index[i]=n-i;
    int p,c;
    for(int k=0;k<r;++k){
      cin>>p>>c;
      int cnt=0;
      while(cnt!=c){
	int tmp=index[p-1+cnt];
	for(int j=0;j<p-1;++j)
	  index[p-j+cnt]=index[p-j-1+cnt];
	index[0]=tmp;
	++cnt;
      }
    }
    cout<<index[0]<<endl;
  }
  return 0;
}

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

int main() {
	int n, r;
	while(cin >> n >> r, n || r) {
		vector<int> v(n);
		iota(v.rbegin(), v.rend(), 1);
		
		for(int i = 0; i < r; ++i) {
			int p, c;
			cin >> p >> c;
			p--;
			auto temp = v;
			for(int j = 0; j < c; ++j) {
				temp[j] = v[p + j];
			}
			
			for(int j = 0; j < p; ++j) {
				temp[c + j] = v[j];
			}
			
			swap(v, temp);
		}
		cout << v[0] << endl;
	}
	return 0;
}

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

int main(){
	int hanafuda[51]{0};
	int tmpp[51]{0};
	vector<int> ansvec;

	for (;;){
		int n, r;
		cin >> n >> r;
		if (n == 0) break;

		for (int i = n; i >= 1; i--){
			hanafuda[i] = i;
		}

		for (int i = 0; i < r; i++){
			int p, c;
			cin >> p >> c;
			for (int j = 0; j < p - 1; j++){
				tmpp[p - 1 - j] = hanafuda[n - j];
			}
			for (int j = 0; j < c ; j++){
				hanafuda[n - j] = hanafuda[n - (p - 1) - j];
			}
			for (int j = 0; j < p - 1; j++){
				hanafuda[n - c - j] = tmpp[p - 1 - j];
			}
		}
		ansvec.push_back(hanafuda[n]);
	}

	for (int ans : ansvec){
		cout << ans << endl;
	}

	return 0;
}

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

using namespace std;

int main(void)
{
	int n, r;
	while(cin >> n >> r && n > 0){
		vector<int> card(n);
		//cardを初期化
		for(int i=0;i<n;i++){
			card[i] = n-i;
		}
		for(int i=0;i<r;i++){
			int p, c;
			cin >> p >> c;
			rotate(card.begin(), card.begin()+p-1, card.begin()+p+c-1);
		}
		cout << card[0] << endl;
	}
	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<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;
	while(1){
		cin>>n>>r;
		if(n==0&&r==0)
			break;
		int *hanahuda=new int[n];

		for (int i = n-1; i>=0 ; i--)
			hanahuda[i]=n-i;

		for(int i=0;i<r;i++){
			cin>>p>>c;
			top=top_search(n,p,c,hanahuda);
			cout<<top<<endl;
		}
		delete[] hanahuda;
		cnt++;
	}
	for(int m=0;m<cnt;m++)
		
	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>
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;
			}
			for(int k=0;k<n;k++)
				cout << card[k] << "\n";
			cout << "\n";

		}
	
	}
	return 0;
}

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

using namespace std;

int solve(int n,int r){
    vector<pair<int,int> >p;
    for(int i=0;i<r;i++){
        int a,b;
        cin >> a >> b;
        p.push_back(make_pair(a,b));
    }

    int x = 1;
    for(vector<pair<int,int> >::iterator it=p.end();
        it != p.begin();
        --it){
        int a = (*it).first;
        int b = (*it).second;
        if(x<=b){
            x = x + a - 1;
        }else if(x<=a+b){
            x = x - b;
        }
    }
    cout << n-x+1 << endl;
}

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