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<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
using namespace std;

#define ll long long
#define MP make_pair

int main(void) {
    int n,r;
    while(1){
        cin>>n>>r;
        if(n==0&&r==0)break;
        vector<int> v(50);
        for (int i = 0; i < n; i++) {
            v[i]=n-i;
        }



        int p,c;
        for (int i = 0; i < r; i++) {
            vector<int> tmp;
            cin>>p>>c;
            copy(v.begin()+p-1,v.begin()+p+c-1,back_inserter(tmp));
            /*for (int l = 0; l < tmp.size(); l++) {
                cout<<"tmp"<<tmp[l]<<"\n";
            }*/
            v.erase(v.begin()+p-1,v.begin()+p+c-1);
            v.insert(v.begin(),tmp.begin(),tmp.begin()+c);
            /* for (int k = 0; k < n; k++) {
                cout<<"v"<<v[k]<<"\n";
            }*/
        }

        cout<<v[0]<<"\n";
    }
    
    
    return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <fstream>
#include <stdint.h>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define FOR(i, l, r) for(int i = l; i < r; i++)
#define RFOR(i, l,r) for(int i= (l)-1; i>= (r) ; i--)

template<typename stl>
void show_vec(const stl& x)
{
    for(auto i : x)
        cerr << i << ' ';
    cerr << '\n';
}

void swap_range(vector<int>& dek, int l, int k)
{
    vector<int> ret;
    int r = l + k;
    /* cerr << "l : r" << l  << ':' << r << '\n'; */
    FOR(i, l, r)
    {
        /* cerr << "i:" << i << ' '; */
        ret.push_back(dek[i]);
    }
    /* cerr << "ret1:: " ; show_vec(ret); */
    REP(i, l)
        ret.push_back(dek[i]);
    /* cerr << "ret2:: " ; show_vec(ret); */
    FOR(i, l+k, dek.size())
        ret.push_back(dek[i]);
    /* cerr << "ret3:: " ; show_vec(ret); */
    dek = ret;
}


int main()
{
    ios::sync_with_stdio(false);
    int n, r;
    while(cin >> n >> r)
    {
        if(n == 0)
            return 0;
        vector<int> dek;
        RFOR(i, n+1, 1)
            dek.push_back(i);
        /* show_vec(dek); */
        REP(i, r)
        {
            int p, c;
            cin >> p >> c;
            swap_range(dek, p-1, c);
            /* show_vec(dek); */
        }
        cout << dek[0] << '\n';
    }
}

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

void show(vector<int> a){
  for(int i=0;i<a.size();i++){
    cout << a[i] << endl;
  }
  cout << endl;
}
int main(){
  while(1){
    int N,R;
    cin >> N >> R;
    if(N==0&&R==0)break;
    vector<int> a;
    for(int i=N;i>=1;i--){
      a.push_back(i);
    }
    for(int i=0;i<R;i++){
      int p,c;
      cin >> p >> c ;
      vector<int> b;
      for(int j=0;j<c;j++){
        b.push_back(a[p-1+j]);
      }
      a.erase(a.begin()+p-1,a.begin()+p-1+c);
      a.insert(a.begin(),b.begin(),b.end());
    }
    cout << a[0] << endl;
  }
}

C++: #include <stdio.h>

int main(){

  int n,r,p,c,i,j;
  int score[51];
  int temp[51];

  scanf("%d%d",&n,&r);

  for(i=1;i<=n;i++){
    score[i]=i;
    temp[i]=i;
  }

  for(i=1;i<=r;i++){
    scanf("%d%d",&p,&c);

    for(j=n-p+1;j>n-p+1-c;j--){
      score[j+p-1]=score[j];
    }
     for(j=n;j>=n-p+1;j--){
     score[j-c]=temp[j];
     }

  }

  printf("%d\n",score[n]);

  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){
    //?±±??????????????????                                                            
    yama.clear();
    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] << endl;
  }
  cout << endl;
}

void shuffle(vector<int> &yama, int n, int p, int c){
  int tmp;

  for(int i = 0;i < c; i++){
    tmp = yama[p-1+c-1];
    yama.erase(yama.begin()+p-1+c-1);
    yama.insert(yama.begin(), tmp);
    for(int j = 0; j < yama.size(); j++){
      cout << yama[j] << " ";
    }
    cout << endl;

  }
}

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

int erase_alt(list<int> &lis, list<int>::iterator itr)
{
	int temp = *itr;
	lis.erase(itr);
	return temp;
}

int main()
{
	while (true)
	{
		list<int> list0;
		int n, r;
		cin >> n >> r;
		if (n == 0 && r == 0)break;
		for (int i=n; i > 0; i--)
		{
			list0.push_back(i);
		}
		for (int i = 0; i<r; i++)
		{
			int p, c;
			list<int>::iterator itr = list0.begin();
			cin >> p >> c;
			if (p == 1)continue;
			advance(itr, p - 1);
			list0.splice(list0.begin(), list0, itr, next(itr, c));

		}
		cout << *list0.begin() << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
  int n,r;
  cin >> n >> r;
  if(n==0&&r==0) break;
  vector<int> a(n);

  for(int i=0;i<a.size();i++){
    a[i] = n-i;
    //cout << a[i] << endl;
  }
  for(int k=0;k<r;k++){
  int p,c;
  cin >> p >> c;
  vector<int> tori(c),tmp(p-1);

    for(int i=0;i<(p-1);i++){
      tmp[i]=a[i];
      //cout << endl << tmp[i] << endl << endl;
    }
    for(int i=0;i<c;i++){
      tori[i]=a[(p-1)+i];
      //cout << tori[i] << endl;
    }
    /*for(int i=0;i<c;i++){
      cout << tori[i] << endl;
    }*/
    for(int i=0;i<c;i++){
      a[i]=tori[i];
    }
    int j=0;
    for(int i = c;i<(c+p-1);i++){
      a[i] = tmp[j];
      j++;
    }

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

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[51];	//山
	int temp[51];	//一時的に保存しておく
	int ans[51];	//答えを保存しておく
	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];
			}
		}
		std::cout << n1[0] << std::endl;
		//ans[j++] = n1[0];
	}

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

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

int main() {
    while (true) {
        int n, m;
        cin >> n >> m;
        if (n == 0 && m == 0) break;
        vector<int> c(n);
        for (int i = 0; i < n; ++i) c[i] = n-i;
        for (int i = 0; i < m; ++i) {
            int p, r; cin >> p >> r;
            rotate(c.begin(), c.begin()+p-1, c.begin()+p+r-1);
        }
        cout << c[0] << endl;
    }
}