Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		n, _ := strconv.Atoi(chunks[0])
		r, _ := strconv.Atoi(chunks[1])
		cards := make([]int, n, n)
		for i := 0; i < n; i++ {
			cards[i] = n - i
		}
		for i := 0; i < r; i++ {
			sc.Scan()
			chunks := strings.Split(sc.Text(), " ")
			p, _ := strconv.Atoi(chunks[0])
			c, _ := strconv.Atoi(chunks[1])
			block := make([]int, c, c)
			for j := 0; j < c; j++ {
				block[j] = cards[p+j-1]
			}
			for j := p - 2; j >= 0; j-- {
				cards[j+c] = cards[j]
			}
			for j := 0; j < c; j++ {
				cards[j] = block[j]
			}
		}
		fmt.Println(cards[0])
	}
}

C++: #include <bits/stdc++.h>
const long long INF = LLONG_MAX/2;
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ll long long int
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

using namespace std;
ll ans = 0;

ll n, r, a, b;
vector<ll> v, w;

int main()
{
	while (true){
		cin >> n >> r;
		if (!n&&!r) return 0;
		w.resize(n);
		v.resize(n);
		FOR(i, 1, n + 1) v[i - 1] = n - i + 1;
		REP(i, r)
		{
			cin >> a >> b;
			REP(j, b)
			{
				w[j] = v[j + a - 1];
			}
			REP(j, a - 1)
			{
				w[j + b] = v[j];
			}
			FOR(j, a + b - 1, n)
			{
				w[j] = v[j];
			}
			v.clear();
			copy(w.begin(), w.end(), back_inserter(v));
		}
		cout << v[0] << endl;
	}
}

C++: #include <iostream>

using namespace std;

int main()
{
    int n, r;

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

        for (int i = 1; i <= 50; i++) 
            card[i] = i;


        for (int i = 0; i < r; i++) {
            int p, c;
            
            cin >> p >> c;
            for (int j = 0; j < c; j++) 
                tmp[j] = card[n - p - c + 2 + j];

            for (int j = 0; j < p - 1; j++) 
                card[n - p - c + 2 + j] = card[n - p + 2 + j];
            for (int j = 0; j < c; j++)
                card[n - c + 1 + j] = tmp[j];
        }
        
        cout << card[n] << endl;
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int n,r, p,c;
  string pile, buf, next;
  while(cin>>n>>r&&(n||r)){
    pile=" ";
    for( int i=n;i>0;i-- )
      pile = pile + (char)i;
    while(r--){
      cin>>p>>c;

      next = " " + pile.substr(p,c);
      if( p != 1)
	next += pile.substr(1, p-1);
      if( c != (int)pile.length() )
	next += pile.substr(p+c);

      pile = next;
    }
    cout << (int)pile[1] << endl;
  }
  return 0;
}

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

int main() {
	int n,r;
	int p,c;
	while(1)
	{
		cin>>n>>r;
		if(n==0||r==0)
		{
			break;
		}
		int i=1;
		int a[n];
		int b[n];
		for(i=0;i<n;i++)
		{
			a[i]=n-i;
			b[i]=0;
		}
		i=0;
		while(r!=i)
		{
			cin>>p>>c;
			int j;
			for(j=0;j<c;j++)
			{
				b[j]=a[j+(p-1)];
			}
			for(j=0;j<p-1;j++)
			{
				b[c+j]=a[j];
			}
			for(j=0;j<p+c;j++)
			{
				a[j]=b[j];
			}
			i++;
		}
		cout<<a[0]<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
  int n,r,p,c;
  vector<int> ans;
  while(cin >> n,n){
    cin >> r;
    vector<int> v,q;
    for(int i = n;i > 0;i--)v.push_back(i);
    for(int i = 0;i < r;i++){
      cin >> p >> c;
      for(int j = 0;j < p - 1;j++)q.push_back(v[j]);
      for(int j = p - 1;j < p + c - 1;j++)v[j - p + 1] = v[j];
      for(int j = c;j < p + c - 1;j++)v[j] = q[j - c];
    }
    ans.push_back(v[0]);
  }
  for(int i = 0;i < ans.size() - 1;i++)cout << ans[i] << endl;
  cout << ans[ans.size() - 1];
}

C++: /*** ??±????????£????????? ***/

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

int main(){
	int n, r;
	int p, c;
	int x;
	vector<int> huda;
	vector<int>::iterator itr;
	
	cin >> n;
	cin >> r;
	for(int i=0; i<n; i++) huda.push_back(i+1);
	
	while(n!=0 && r!=0){
		for(int i=0; i<r; ++i){
			cin >> p;
			cin >> c;
			
			for(int j=0; j<c; ++j){
				itr = huda.begin()+(n-p);
				huda.push_back(*itr);
				huda.erase(huda.begin()+(n-p));
			}
		}
		
		cout << *huda.end() << endl;
		
		cin >> n;
		cin >> r;
		for(vector<int>::iterator it=huda.begin(); it!=huda.end(); it++){
			cout << *it << endl;
		} 
		cout << endl;
		huda.clear();
		for(int i=0; i<n; i++) huda.push_back(i+1);
	}
	
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#define pi 3.14159
using namespace std;


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


	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    while(true){
        int n,r; 
        cin>>n>>r; 
        if(n==0&&r==0)
            break; 
        vi res(n); 
        rep(i,0,n)
            res[i]=n-i; 
        rep(i,0,r){
            int p,c; 
            cin>>p>>c; 
            vi st(p-1); 
            //上からp-1枚保管
            rep(j,0,p-1){
                st[j]=res[j]; 
            }
            //c枚を上に
            rep(j,0,c){
                res[j]=res[p-1+j];
            }
            //p-1枚を下に
            rep(j,0,p-1){
                res[j+c]=st[j]; 
            }
        }
        cout<<res[0]<<endl; 
    }
       
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)

int main(){
    int n, r;
    while(cin >>n >>r && n){
        vector<int> v;
        for(int i = n; i >= 1; --i) v.push_back(i);

        REP(i, r){
            int p, c;
            cin >>p >>c;
            vector<int> nv;
            FOR(j, p - 1, p + c - 1) nv.push_back(v[j]);
            FOR(j, 0, p - 1) nv.push_back(v[j]);
            FOR(j, p + c - 1, n) nv.push_back(v[j]);
            v = nv;
        }
        cout <<v[0] <<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<iomanip>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{"; for(auto nth : list){ cout << nth << " ";}cout << "}" << endl;

using namespace std;

int main(){

	while(true){
		int a,b;
		cin >> a >> b;
				
		if(a==0&&b==0) break;

		int card[a];
		
			for(int i=a;0<i;i--){
				card[a-i]=i;
			}
			for(int i=0;i<b;i++){
				int c,d;
				cin >> c >> d;
				rotate(card,card+c-1,card+c+d-1);
			}
			cout << card[0] << endl;

	}
}