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<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n||m){
    string in;
    rep(i,n)in=(char)(i+49)+in;

    rep(i,m){
      int a,b;
      cin>>a>>b;
      //cout<<in<<endl;
      in=in.substr(a-1,b)+in.substr(0,a-1)+in.substr(a+b-1);
    }
    cout<<in[0]-'0'<<endl;
  }

}

C++: arr=[]
ta=[]
while true do
  n, r = gets.split.map(&:to_i)
  if n == 0 && r == 0
    break
  end
  arr = (1..n).to_a.reverse
  r.times do
        p, c = gets.split.map(&:to_i)
        p -= 1
        ta = arr[p...p+c] + arr[0...p] + arr[p+c..n]
        arr = ta
  end
  puts arr[0]
end

C++: #include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
#define ll long long
#define pb push_back

int main()
{
    int n, r, j=0,c;
    vector<int> x;

    while (1)
    {
        cin >> n >> r;
        if (n == 0 || r == 0)
        {
            break;
        }
        vector<int> a(n);
        for(int i=1;i<=n;i++){ // a[n] を一番上とする
            a[i-1] = i;
        }
        int p,c;
        for (int i = 0;i<r;i++)
        {
            cin >> p >> c;
            for(int j = 0; j < c; j++){
                a.push_back(a[n-p-c+1]); // p番目を取り出す
                a.erase(a.begin()+(n-p-c+1));
            }
            // for(int i=0;i<n;i++){ // a[n] を一番上とする
            //     cout << a[i];
            // }
            // cout << endl;
        }
        x.push_back(a[n-1]);
        j++; 
    }
    for(int i=0;i<j;i++){
        cout << x[i] << endl;
    }
}

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

#define ll long long int
#define ld long long double
#define reps(i,f,n) for(int i=f;i<n;i++)
#define rep(i,n) reps(i,0,n)
#define m1 cout<<"move1"<<endl
#define m2 cout<<"move2"<<endl
#define m3 cout<<"move3"<<endl
#define m4 cout<<"move4"<<endl


int main(){
  ll N,R;
  vector<int> v;
  ll a,b;
  vector<int> c;
  
  while(cin>>N,cin>>R,N != 0 && R != 0){
    rep(i,N)v.insert(v.begin(),i);
    rep(i,R){
      cin>>a>>b;
      for(int i=a-1;i< a+b-1;i++) c.push_back(v[i]);
      v.erase(v.begin() + a - 1, v.begin() + a - 1 + b);
      for(int i=0;i < c.size();i++)v.insert(v.begin()+ i,c[i]);
      c.clear();
    }
    cout<<v[0] + 1 <<endl;
    v.clear();
  }
  return 0;
}

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

using namespace std;

int main(void){
  int n, r, p, c;
  vector<int> v, buf1, buf2;

  while(cin >> n >> r, n || r){
    v.clear();
    for(int i=1; i<=n; i++){
      v.push_back(i);
    }

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

      buf1.clear();  buf2.clear();
      for(int j=0; j<v.size(); j++){
        if(j < n-p-(c-1) || n-p < j){
          buf1.push_back(v[j]);
        } else {
          buf2.push_back(v[j]);
        }
      }

      v.clear();
      for(int j=0; j<buf1.size(); j++){
        v.push_back(buf1[j]);
      }
      for(int j=0; j<buf2.size(); j++){
        v.push_back(buf2[j]);
      }
    }

    cout << v[v.size()-1] << endl;
  }

  return 0;
}

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

using namespace std;

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

vector<int> subvec(vector<int> vec,int a,int b){
	vector<int> ret(b);
	for (int i = 0; i < b; i++){
		ret[i] = vec[i+a];
	}
	return ret;
}


int main(){
	while(1){
		int n; cin >> n;
		int r; cin >> r;
		if (n == 0 and r == 0) break;
		vector<int> str(n);

		for (int i = n; i > 0; i--){
				str[n-i] = i;
		}
		for (int i = 0; i < r; i++){
			vector<int> tmp;
			int p,c; cin >> p >> c;
			vector<int> str1 = subvec(str,0,p-1);
			vector<int> str2 = subvec(str,p-1,c);
			vector<int> str3 = subvec(str,p+c-1,str.size()-p-c+1);

			copy(str2.begin(),str2.end(),back_inserter(tmp));
			copy(str1.begin(),str1.end(),back_inserter(tmp));
			copy(str3.begin(),str3.end(),back_inserter(tmp));
			str = tmp;
		}
		cout << str[0] << endl;
	}		
	return 0;
}

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

int main()
{
    int before[60],after[60];
    int n,r;
    while(cin >> n >> r)
    {
        if(n==0 && r==0)break;
        for(int i=0;i<n+1;i++)
        {
            before[n-i]=i+1;
            after[n-i]=i+1;
        }
        
        int p,c,temp;
        for(int i=0;i<r;i++)
        {
            cin>>p>>c;
            for(int j=0;j<c;j++)
            {
                after[j+1]=before[p+j];
            }
            for(int j=0;j<p-1;j++)
            {
                after[c+j+1]=before[j+1];
            }
            for(int j=0;j<55;j++)
            {
                before[j]=after[j];
            }
        }
        cout << after[1]<< endl;
    }

    return 0;
}

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

int n,r;
int s,t;
int deck1[50],deck2[50];

void shuffle(int p,int c);

int main()
{
        while(cin >> n >> r){
                if(n==0 && r==0) break;
                for(int i=0;i<n;i++){
                        deck1[i] = n-i;
                }

                for(int i=0;i<r;i++){
                        cin >> s >> t;
                        shuffle(s,t);
                }

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

        return 0;
}

void shuffle(int p,int c)
{
        for(int i=0;i<c;i++) deck2[i] = deck1[p-1+i];
        for(int i=0;i<p-1;i++) deck2[c+i] = deck1[i];
        for(int i=0;i<c+p-1;i++) deck1[i] = deck2[i];
}

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

int main(void)
{
	while(1)
	{
		int num, action;
		cin>>num>>action;
		if(num == 0 && action == 0)
			break;

		vector<int> cards(num);
		for(int i= 0; i < num; i++)
			cards[i]= num-i;

		for(int i= 0; i < action; i++)
		{
			int startc, numc;
			cin>>startc>>numc;
			vector<int> res(num);

			for(int j= 0; j < numc; j++)
				res[j]= cards[startc-1+j];
			for(int j= 0; j < startc-1; j++)
				res[numc+j]= cards[j];
			for(int j= startc+numc-1; j < num; j++)
				res[j]= cards[j];
			for(int j= 0; j < num; j++)
				cards[j]= res[j];
		}
		cout<<cards[0]<<endl;
	}
}

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

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