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 <vector>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <ctime>
#include <iterator>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

void rotation(vector<int> &v,int fin)
{
    int tmp = v[fin];
    for(int c=fin;c>=1;c--)
    {
        v[c]=v[c-1];
    }
    v[0]=tmp;
}

int main()
{
    int n,r;
    while(cin>>n>>r)
    {
        if(n==0) break;
        vector<int> v(n);
        for(int c=0;c<n;c++) v[c]=n-c;
        for(int c=0;c<r;c++)
        {
            int a,b;
            cin>>a>>b;
            for(int c2=0;c2<b;c2++)
            {
                rotation(v,b+a-2);
            }
        }
        cout<<v[0]<<endl;
    }
}

C++: #include<iostream>
#include<vector>
struct num{
  int c,p;
};
std::vector<int> push(std::vector<int> recv,int p,int c){
  std::vector<int> vec;
  for(int i=p-1;i<=p+c-2;++i){
    vec.push_back(recv[i]);
  }
  return vec;
}
std::vector<int> cp(std::vector<int> recv,std::vector<int> recv2){
  std::vector<int> vec;
  for(int i=0;i<recv.size();++i){
    vec.push_back(recv[i]);
  }
  for(int i=0;i<recv2.size();++i){
    vec.push_back(recv2[i]);
  }
  return vec;
}
int main(){
  while(1){
  std::vector<num> vec;
  std::vector<int> f;
  int n,r;
  std::cin>>n>>r;
  if(n==0&&r==0)return 0;
  for(int i=0;i<n;++i){
    f.push_back(n-i);
  }
  for(int i=0;i<r;++i){
    num n;
    std::cin>>n.p>>n.c;
    vec.push_back(n);
  }
  for(int i=0;i<vec.size();++i){
    std::vector<int> vec2;
    vec2=push(f,vec[i].p,vec[i].c);
    f=cp(vec2,f);
  }
  std::cout<<f[0]<<std::endl;
  }
}

C++: #include <iostream>
#include <cstdio>
//#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
//#include <stack>
//#include <limits>
#include <sstream>
//#include <functional>
using namespace std;

#define len(array)  (sizeof (array) / sizeof *(array))
#define rep(i, s, e) for(int i = s;i < e;i++)
#define rrep(i, e, s) for(int i = e;s <= i;i--)
#define vrange(v) v.begin(), v.end()
#define vrrange(v) v.rbegin(), v.rend()
#define vsort(v) sort(vrange(v))
#define vrsort(v) sort(vrrange(v))
#define arange(a) a, a + len(a)
#define asort(a) sort(arange(a))
#define arsort(a, t) sort(arange(a), greater<t>())
#define afill(a, v) fill(arange(a), v)
#define afill2(a, v, t) fill((t *)a, (t *)(a + len(a)), v)
#define fmax(a, b) (a < b? b : a)
#define fmin(a, b) (a > b? b : a)
#define fabs(a) (a < 0? -a : a)
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-10;
//const int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
//const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
//const int weight[] = {0,1,10,100,1000,10000,100000,1000000,10000000};
//priority_queue< int, vector<int>, greater<int> > q;

void doIt(){
	int n, r, count = 0, p1, c1, res;
	string s = "", pre, mid,suf;
	while(true){
		cin >> n >> r;
		if(n + r == 0) break;
		s = "";
		count = 0;
		for(char c = 'a'; c <= 'z'; c++){
			if(count < n) s += c;
			count++;
		}
		for(char c = 'A'; c <= 'X'; c++){
			if(count < n) s += c;
			count++;
		}
		while(r--){
			cin >> p1 >> c1;
			pre = s.substr(0, p1-1);
			mid = s.substr(p1-1, c1);
			suf = s.substr(c1+p1-1);
			// cout << pre << endl;
			// cout << mid << endl;
			// cout << suf << endl;
			s = mid + pre + suf;
			// cout << s << endl;
		}
		if('a' <= s[0] && s[0] <= 'z'){
			res = s[0] - 'a';
		}
		else{
			res = s[0] - 'A';
		}
		cout << n - res << endl;

	}

}

int main() {
	doIt();
	return 0;
}

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

using namespace std;

int main() {
	int n, r;
	while (cin >> n >> r, n + r != 0) {
		vector<int> cards(n);
		for (int i = 0; i < n; i++) {
			cards[i] = i + 1;
		}
		for (int i = 0; i < r; i++) {
			int p, c;
			cin >> p >> c;
			for (int j = 0; j < c; j++) {
				cards.push_back(cards[n - (p - 1 + c)]);
				cards.erase(cards.end() - (p + c));
			}
		}
		cout << cards[n - 1] << endl;
	}

	return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する

void solve(int n,int m){
    vector<int> v(n);
    rep(i,0,n){
        v[i] = i + 1;
    }
    rep(i,0,m){
        int p,c;
        cin >> p >> c;
        vector<int> tmp1(v.end() - p + 1 ,v.end());
        vector<int> tmp2(v.end() - p + 1 - c,v.end() - p + 1);

        rep(j,0,tmp1.size()){
            v[v.size() - p + 1 - c + j] = tmp1[j];
        }
        rep(j,0,tmp2.size()){
            v[v.size() - p + 1 - c + tmp1.size() + j] = tmp2[j];
        }


    }
    cout << v.back() << endl;

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    while(true){
        int n,m;
        cin >> n >> m;
        if(n == 0) break;
        solve(n,m);

    }


    return 0;
}

C++: #include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


void printv(vector<int> v) {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i] << " ";
	}
	cout << endl;
}
int main() {
	
	while(1) {
		int n,r; cin >> n >> r;
		if(n + r == 0) {
			break;
		}

		vector<int> H(n,0);
		for (int i = 0; i < n; i++) {
			H[i] = n - i;
		}

		for (int j = 0; j < r; j++) {
			vector<int> a;
			vector<int> b;
			int p,c; cin >> p >> c;
			for (int i = 0; i < p-1; i++) {
				a.push_back(H[i]);
			}
			//cout << "a" << endl;
			//printv(a);
			for (int i = p - 1; i < p - 1 + c; i++) {
				b.push_back(H[i]);
			}
			//cout << "b" << endl;
			//printv(b);
		
			for (int i = 0; i < c; i++) {
				H[i] = b[i];
			}
			//cout << "H1" << endl;
			//printv(H);
			for (int i = 0; i < p - 1; i++) {
				H[c + i] = a[i];
			}
			//cout << "H2" << endl;
			//printv(H);
		}
		cout << H[0] << endl;
	}


	return 0;
}