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<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 <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
	int n, r;
	vector<int> card;
	vector<int> card2;
	while(true){
		cin >> n >> r;
		if(!n && !r) break;
		card.clear();
		// 1 .. n
		for(int i = 1; i <=n ; i++){
			card.push_back(i);
		}

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

			cin >> p >> c;
			if(n == c) continue;
			
			vector<int>::iterator it = card.end() - p - c + 1;
			
			// temp
			for(int j = 0; j < c; j++){
				card.push_back(*it);
				it++;
			}
			
			
			//erase
			card.erase(it  - c, it);
			
			it = card.begin();
			while(it != card.end()){
				cout << " " << *it ;
				it ++;
			}
			cout << endl;
			
		}
		cout << card[n-1] << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

ll v[100];

int main()
{
	cin >> n >> k;
	if (n == 0 && k == 0) {
		return 0;
	} else {
		vi v(n + 1);
		REP(i, n + 1)
			v[i] = n + 1 - i;
		REP(i, k)
		{
			ll p, c;
			cin >> p >> c;
			REP(j, c)
			{
				ll tmp = v[p + j];
				for (int l = p; l >= 1; l--) {
					v[j + l] = v[j + l - 1];
				}
				v[j + 1] = tmp;
			}
		}
		cout << v[1] << endl;
	}
}

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

int main() {
    int N, R;
    while (cin >> N >> R, N || R) {
        vector<int> v(N);
        for (int i = 0; i < N; i++) {
            v[i] = i+1;
        }

        while (R--) {
            int p, c;
            cin >> p >> c;
            auto w = v;
            for (int i = 0; i < p-1; i++) {
                w[N - p - c + i + 1] = v[N - p + i + 1];
            }

            for (int i = 0; i < c; i++) {
                w[N - c + i] = v[N - p - c + i + 1];
            }

            v = w;
        }

        cout << v[N-1] << endl;
    }

    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(s) (s).begin(),(s).end()
#define ITE(c) typeof((c).begin())

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

using namespace std;

int main(){
	int n, r, p, c;
	vector<int> ls;
	while(cin>>n>>r&&n||r){
		ls.clear();
		for(int i=n;i>0;i--){
			ls.push_back(i);
		}
			
		rep(j,r){
			cin>>p>>c;
			vector<int> tmp;
			for(int i=p-1;i<p+c-1;i++){
				tmp.pb(ls.at(i));
			}
			ls.erase(ls.begin()+p-1,ls.begin()+p+c-1);
			EACH(i,ls){
				tmp.pb((*i));
			}
			ls.clear();
			EACH(i,tmp){
				ls.push_back((*i));
			}
		}
		cout<<ls.at(0)<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
	int card[50][50]={0};
	int mem[50]={0};
	int n;
	int r;
	int k = 0 ;
	int p,c;
	while(1){
		cin >>n >>r;
		if ((n==0)&&(r==0)) break;
		for(int i =0;i<n;i++){
			card[k][i]=i+1;
		}	
		for (int j=0;j<r;j++){
			cin >> p >> c ;
			for(int l=0;l<n;l++){
				mem[l]=card[k][l];
			}
			for(int m=0;m<p-1;m++){
				card[k][n-p-c+1+m]=mem[n-p+1+m];
			}
			for(int o=0;o<c;o++){
				card[k][n-c+o]=mem[n-p-c+1+o];
			}
		}
		cout << card[k][n-1] <<endl;
		k++;

	}
	
	return 0;
}

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

int main()
{
  int n,r;
  int p,c;
  
  while(cin >> n >> r,n||r){

    vector<int> card(n,0);
    for(int i=0;i < n;i++){
      card[i]=i+1;
    }
    reverse(card.begin(),card.end());
    
    for(int i=0;i < r;i++){
      cin >> p >> c;
      rotate(card.begin(),card.begin()+p-1,card.begin()+p-1+c);
      
      // rotate(a,b,c):= [a,b)と[b,c)を入れ替え
    }
    cout << *card.begin() << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
    while (true) {
        int n, r, a[50];

        cin >> n >> r;
        if ( n == 0 && r == 0) { break; }

        for (int i = 0; i < n; i++) {
            a[i] = n-i;
        }

        for (int i = 0; i < r; i++) {
            int p, c;
            cin >> p >> c;
            rotate(a, a+p-1, a+p+c-1);
        }

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

    return 0;
}

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

int n, r;
int head, val[51], nxt[51];

int main() {
	while (cin >> n >> r, n) {
		head = 0;
		for (int i=0; i<n; ++i) {
			val[i] = n-i;
			nxt[i] = i+1;
		}
		
		for (int i=0; i<r; ++i) {
			int p, c;
			cin >> p >> c;
			if (p == 1) continue;
			
			int it_p = head;
			while (p>2) it_p = nxt[it_p], --p;
			
			int it_c = it_p;
			while (c) it_c = nxt[it_c], --c;
			
			int tmp = head;
			head = nxt[it_p];
			nxt[it_p] = nxt[it_c];
			nxt[it_c] = tmp;
		}
		
		cout << val[head] << endl;
	}
}