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 <bits/stdc++.h>
using namespace std;

int p[60], c[60];

int main(){
    int n, r;
    while(cin >> n >> r && (n | r)){
        for(int i=0;i<r;i++)
            cin >> p[i] >> c[i];
        
        int target = 1;
        for(int i=r-1;i>=0;i--){
            int t = p[i] - 1 + c[i];
            
            if(target > t)
                continue;
        
            if(target <= c[i]){
                target = p[i] - 1 + target;
            } else {
                target = target - c[i];
            }
        }
        
        cout << n + 1 - target << endl;
    }
    
    return 0;
}

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

using namespace std;
int N,R,p,c;

int main() {
	while (cin >> N >> R && N) 
	{
		//		cout << N <<  " " << R << endl;
		int M[N];
		for (int i = 0; i < N; ++i)
		{
			M[i] = N-i;
		}
		//for (int i = 0; i < N; ++i)
		//{
		//	cout << M[i] << endl;
		//}
		for (int i = 0; i < R; ++i)
		{
			cin >> p >> c;
			rotate(M,M+p-1,M+p+c-1);
		//			cout << p << " " << c << endl;
		}
		cout << M[0] << endl;
	}
}

C++: #include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

vector<int> ans;

int solve(int n, int r){
    vector<int> cards(n);
    for (int i = n-1; i >= 0; i--){
        cards[i] = n-i;
    }

    for (int i = 0; i < r; i++){
        int p, c; cin >> p >> c;
        vector<int> tmp;
        for (int j = p-1; j < p-1+c; j++){
            tmp.push_back(cards[j]);
        }
        for (int j = 0; j < p-1; j++){
            tmp.push_back(cards[j]);
        }
        for (int j = p-1+c; j < n; j++){
            tmp.push_back(cards[j]);
        }
        cards = tmp;
    }
    return cards[0];
}


int main(){
    cin.tie(0);

    while (1){
        int N, R; cin >> N >> R;
        if (!N && !R) break;
        ans.push_back(solve(N, R));
    }
    for (auto itr = ans.begin(); itr != ans.end(); itr++){
        cout << *itr << endl;
    }
}

C++: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M;
	while (N) {
		long long int num[50] = {};
		for (int i = 0; i < N; i++) {
			num[i] = (N-i) * MOD + i + 1;
		}
		for (int i = 0; i < M; i++) {
			cin >> K >> Q;
			for (int j = 0; j < N; j++) {
				if (num[j] % MOD < K) {
					num[j] += Q;
				}
				else if (num[j] % MOD < K + Q) {
					num[j] -= (K - 1);
				}
			}
		}
		for (int i = 0; i < N; i++) {
			if (num[i] % MOD == 1)cout << num[i] / MOD << endl;
		}
		cin >> N >> M;
	}
	return 0;
}

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

int main()
{
  list<int> l,ll;
  list<int>::iterator start,end;
  int n,r,i,p,c;
  while(cin>>n>>r,n||r){
    l.clear();
    for(i=1;i<=n;i++)l.push_front(i);
    while(r-->0){
      cin>>p>>c;
      start=end=l.begin();
      advance(start,p-1);
      advance(end,p-1+c);
      ll.clear();
      ll.splice(ll.begin(),l,start,end);
      l.splice(l.begin(),ll);
    }
    cout<<*l.begin()<<endl;
  }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define rep(i, n) for(int i = 0;i < n;i++)
#define reprb(i, n) for(int i = n;i >= 0;i--)
#define reps(i, m, n) for(int i = m;i < n;i++)
#define repsb(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
vector<int> cb,ca,a;

int main(int argc,char * argv[])
{
	int n,r,c,p,cnt=0;
	while(true)
	{
		cin>>n>>r;
		if(n==0&&r==0)	break;
		rep(i,n)	cb.pb(n-i);
		rep(i,r){
			cin>>c>>p;
			reps(j,p,p+c){
				ca.pb(cb[i]);//c
			}
			rep(j,p){
				ca.pb(cb[i]);//p-1
			}
			reps(j,p+c-1,n){
				ca.pb(cb[i]);
			}
			if(i==r-1)	{
				a.pb(cb[0]);
				cnt++;
			}

		}

	}
	rep(i,cnt){
		cout<<a[i]-1<<endl;
	}

	return 0;
}

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

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

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

			vector<int> change;
			// Cツづ個閉板閉ェ
			for(int i=p-1; i<p-1+c; i++){
				change.push_back(card[i]);
			}
			
			// P-1ツづ個閉板閉ェ
			for(int i=0; i<p-1; i++){
				change.push_back(card[i]);
			}
			/*
			for(int i=p-1+c; i<n; i++){
				change.push_back(card[i]);
			}
			*/
			int count=0;
			vector<int>::iterator it = change.begin();
			while(it!=change.end()){
				card[count] = *it;
				count++;
				it++;
			}
		}
		cout << card[0] << endl;
	}
	return 0;
}