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 <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;

const int INF = 1 << 29;
typedef pair<int, int> P;

int n, r;

int main(void)
{
	while(cin >> n >> r && n)
	{
		vector<int> hudas(n);
		for (int i = 0; i < n; i++)
			hudas[i] = n - i;
		for (int i = 0; i < r; i++)
		{
			int p, c;
			cin >> p >> c, p--;

			vector<int> tmp;
			for (int j = 0; j < c; j++)
			{
				tmp.push_back(hudas[p + j]);
			}
			for (int j = 0; j < n; j++)
			{
				if(j < p || j >= p + c)
					tmp.push_back(hudas[j]);
			}
			hudas = tmp;
		}

		cout << hudas[0] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cassert>
#include <deque>
#define REP(i,l,n) for(int i=l;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define MAX 50
using namespace std;
int ans;
int n,r,c,p;
deque<int> deck;
int main() {
  while(1){
    cin >> n >> r;
    if(n==0&&r==0) return 0;
    deck.clear();
    rep(i,n) deck.push_front(i+1);
    rep(i,r){
      cin >> p >> c;
      rep(j,c){
        deck.push_front(deck[p-1+c-1]);
        deck.erase(deck.begin()+p-1+c);
      }
    }
    ans = deck[0];
    cout << ans << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() 
{
	int n,m;
	while(cin >> n >> m && n>0 && m>0)
	{
		int a[50]={0};
		for(int i=0;i<n;i++){	a[i]=n-i;	}
		
		for(int i=0;i<m;i++)
		{
			int x,y;
			cin >> x >> y;
			rotate(a,a+x-1,a+x+y-1);
		}
		cout << a[0] << endl;
	}
	return 0 ;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TEMP_T T    cums(T& v){ T r(v.size()); partial_sum(v.begin(), v.end(), r.begin()); return r; }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }
TEMP_T T    acum(vector<T>& v, T b=0){ return accumulate(v.begin(), v.end(), b); }
TEMP_T vector<T> inpt(int n){ vector<T> v(n); for (int i=0; i<n; i++) cin >> v[i]; return v; }

static inline int in(){ int x; scanf("%d", &x); return x; }

int main()
{
  int n, r;
  while (n = in(), r = in(), n || r){
    deque<int> d(n);
    for (int i = 0; i < n; i++) d[i] = i;
    revs(d);
    for (int i = 0; i < r; i++){
      int p, c;
      p = in() - 1;
      c = in();
      deque<int> buf;
      for (int i = 0; i < c; i++){
        buf.push_front(d[p + i]);
      }
      d.erase(d.begin() + p, d.begin() + p + c);
      for (int i = 0; i < c; i++){
        d.push_front(buf[i]);
      }
    }
    cout << d[0] + 1 << endl;
  }
  return (0);
}

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

#define R input[0][1]

using namespace std;

int input() {
	int input[51][2];
	cin >> input[0][0] >> input[0][1];								//まずnとr
	if (input[0][0] == 0 && input[0][1] == 0) {
		return 0;
	}
	for (char pos = 1; pos <= input[0][1]; pos++) {					//r回のシャッフルの仕方を入力
		cin >> input[pos][0] >> input[pos][1];
	}																//ここまで入力

	/*シャッフルもどし*/
	int whtop = 1;													//最後一番上にいるカードは、今何番目にいる？
	if (R==0)return input[0][0];									//一回もシャッフルしないならコレ

	whtop = input[input[0][1]][0];									//一回目のもどしだけ別枠
	R--;
	while (input[0][1] != 0) {	
		if (whtop <= input[R][1]) whtop = whtop + input[R][0] - 1;
		else if ((input[R][0] + input[R][1] - 1) < whtop) whtop = whtop;
		else whtop = whtop - input[R][1];
		R--;
	}
	return input[0][0] - whtop + 1;

}


int main()
{
	while (1) {
		int check;
		check = input();
		if (check == 0)break;
		else {
			cout << check << endl;
		}
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

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

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n, r;
vector<int> p, c;
void ops(vector<int> &card, int p, int c) {
    auto tmp = card;
    p--;
    rep(i, c) {
        card[i] = tmp[i + p];
    }
    rep(i, p) {
        card[i + c] = tmp[i];
    }
}
void solve() {
    vector<int> card(n);
    rep(i, n) card[i] = n - i;
    rep(i, r) {
        ops(card, p[i], c[i]);
        // rep(i, n) cout << card[i] << " ";
        // cout << endl;
    }
    cout << card[0] << endl;
}
int main() {
    while (cin >> n >> r, n) {
        p.resize(r);
        c.resize(r);
        rep(i, r) cin >> p[i] >> c[i];
        solve();
    }

    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, r, p, c;

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

		vector<int> cards(n);

		for(int i = 0; i < n; ++i) {
			cards.at(n - i - 1) = i + 1;
		}

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

			vector<int> temp_p;
			vector<int> temp_c;

			copy_n(cards.begin(), p - 1, std::back_inserter(temp_p));
			copy_n(cards.begin() + p - 1, c, std::back_inserter(temp_c));

			copy(temp_c.begin(), temp_c.end(), cards.begin());
			copy(temp_p.begin(), temp_p.end(), cards.begin() + c);
		}

		std::cout << cards.at(0) << std::endl;
	}

	return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;

int main(){
        int n,r,table[50],work[50];
        while(cin>>n>>r&&n,r){
                for(int i=0;i<n;i++)table[i]=n-i;
                int p,c;
                for(int i=0;i<r;i++){
                        cin>>p>>c;
                        for(int k=0;k<c;k++)work[k]=table[p-1+k];
                        for(int k=0;k<p-1;k++)work[c+k]=table[k];
                        for(int k=p+c-1;k<n;k++)work[k]=table[k];
                        for(int k=0;k<n;k++)table[k]=work[k];
                }
                cout<<table[0]<<endl;
        }
        return 0;
}

C++: 
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <iomanip>
#include <functional>
using namespace std;
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main(int argc, char* argv[])
{
    int n , r;
    while(cin >> n >> r,n!=0 && r!=0){
        int p,c;
        int i=0,j=0;
        int temp[50];
        int huda[50];
        for(i=0;i<n;i++){
            huda[i] = i+1;
        }
        while(r){
            cin >> p >>c;
            for(i = 0;i < c;i++){
                
                temp[i] = huda[((n-1)-(p-2))-(c-i)];
//                cout << temp[i] << endl;
            }
            
            for (j=p-1; j>0;j-- ) {
                huda[(n-j)-c] = huda[n-j];
            }
//            for(i=0;i<10;i++)cout <<huda[i] <<" ";
//            cout<<endl;
            for(i=0;i<c;i++){
                huda[n-(c-i)] = temp[i];
            }
//            for(i=0;i<10;i++)cout <<huda[i] <<" ";
            r--;
        }
            cout << huda[n-1] << endl;
    }
    return 0;
}