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 <string>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {

    int n, m, p, c, ans;
    string str;
    for (; ;) {
        scanf("%d %d", &n, &m);
        if (n == 0 && m == 0) break;
        str = "";
        for (int i = n; i >= 1; i--) {
            if (i < 10) str+='0';
            str+= to_string(i);
        }
        for (int i = 0; i < m; i++) {
            scanf("%d %d", &p, &c);
            str = str.substr(p*2-2, c*2)+str.substr(0,p*2-2)+str.substr(p*2-2+c*2);
        }
        printf("%d\n", stoi(str.substr(0, 2)));
    }
    return 0;
}

C++: //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1129&lang=jp
//

#include <iostream>
#define rep(i,n) for(int (i) =0;(i) < (n);(i)++)
using namespace std;

void show(int *a,int x){
    for(int i =0;i<x;i++){
        cout << a[i] << endl;
    }
}
int main() {
    int N,R;
    int A[2][55];
    int p,c;
    while(cin >> N >> R && N) {
        for(int i=0; i<N; ++i){
            A[0][i] = N - i;
            
        }
        int now = 0;
        int next = 1;
        rep(i,R){
            cin >> p >> c;
            rep(j,c){
                A[next][j] = A[now][p-1+j];
            
            }
            for(int j=p-1+c; j<N; j++){
                A[next][j] = A[now][j];
            
            }
            for(int j=0; j<p-1; ++j){
                A[next][c+j] = A[now][j];
            }
            int temp = now;
            now = next;
            next = temp;
            
            
        }
        cout << A[now][0] << endl;
        
    }
    
    return 0;
}

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

using namespace std;

const void ShowList(list<int>);

int main() {
	//ifstream fin("input.txt");

	if (!fin)return -1;

	list<int> stock;

	while (true) {

		int number = 0;
		int shuffleCount = 0;
		int top = 0;

		cin >> number >> shuffleCount;
		if (number == 0 && shuffleCount == 0)break;

		//????????????????´??????????(?±±?????????)
		for (int i = 1; i <= number; i++) {
			stock.push_front(i);
		}

//		ShowList(stock);
		list<int>::iterator begin;
			list<int>::iterator end;

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

			if (number == c)continue;
			begin = stock.begin();
			advance(begin, p - 1);
//			cout << "\t" << *begin << endl;

			end = begin;
			advance(end, c);
//			cout << "\t" << *end << endl;

			stock.splice(stock.begin(), stock, begin, end);

		}
//		ShowList(stock);
		cout << stock.front() << endl;

		stock.clear();
	}
	return 0;
}

const void ShowList(list<int> lst){
	list<int>::iterator a = lst.begin();
	for (int i = 0; i < lst.size(); i++) {
		cout << *a << " ";
		a++;
	}
	cout << endl;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  while (true) {
    int n, r;
    cin >> n >> r;
    if (n == 0) return 0;
    vi a(n);
    rep (i, n) {
      a[i] = n - i;
    }
    rep (i, r) {
      int p, c;
      cin >> p >> c;
      p--;
      vi temp;
      for (int j = p; j < p + c; j++) {
        temp.push_back(a[p]);
        a.erase(a.begin() + p);
      }
      temp.insert(temp.end(), a.begin(), a.end());
      a = temp;
    }
    cout << a[0] << endl;
  }
}

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

using namespace std;

int main(){
    for (; ;) {
        int n, r;
        cin >> n >>r;
        if (n==0&&r==0) {
            break;
        }
        vector<int> yama(n);
        for (int i=0; i<n; i++) {
            yama[i]=n-i;
        }
        for (int i=0; i<r; i++) {
            int p ,c;
            cin >> p >> c;
            vector<int> temp(c);
            for (int j=0;j<c; j++) {
                temp[j]=yama[p-1+j];
            }
            for (int j=p-2; j>=0;j--) {
                yama[c+j]=yama[j];
            }
            for (int j=0; j<c; j++) {
                yama[j]=temp[j];
            }
            }
        cout <<yama[0]<<endl;
}
}

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

int main() {
    int n, r;
    while(cin >> n >> r, n) {
        vector<int> v(n);
        for(int i=0; i<n; ++i) {
            v[i] = n-i;
        }
        
        for(int i=0; i<r; ++i) {
            vector<int> tmp;
            int p, c;
            cin >> p >> c;
            tmp.insert(tmp.begin(), v.begin()+p-1, v.begin()+p+c-1);
            v.erase(v.begin()+p-1, v.begin()+p+c-1);
            v.insert(v.begin(), tmp.begin(), tmp.end());
        }
        cout << v[0] << endl;
    }
}