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 main(int argc, char const *argv[])
{
	int n,r;
	while(cin>>n>>r,n+r)
	{
		int a[n],b[n];
		for (int i = 0; i < n; ++i) a[i]=n-i;
		int p,c;
		for (int i = 0; i < r; ++i)
		{
			cin>>p>>c;
			--p;
			for (int i = 0; i < n; ++i) b[i]=a[i];
			for (int i = 0; i < c; ++i) a[i]=b[i+p];
			for (int i = 0; i < p; ++i) a[i+c]=b[i];
		}
		cout<<a[0]<<endl;
	}
	return 0;
}

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

using namespace std;

int main() {
	
	while (1) {
		int n, r; cin >> n >> r; if (n==0 && r==0) break;
		
		vector<int> num(n);
		for (int i=0; i<n; i++) num[i] = n-i;
		
		for (int rep = 0; rep<r; rep++) {
			int p, c; cin >> p >> c;
			
			vector<int> next(n);
			int index = 0;
			for (int i=p-1; i<p+c-1; i++) next[index++] = num[i];
			for (int i=0; i<p-1; i++) next[index++] = num[i];
			for (int i=p+c-1; i<n; i++) next[index++] = num[i];
			
			num = next;
		}
		
		cout << num[0] << endl;
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<17,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N,R;cin>>N>>R;
        if(N==0&&R==0) return 0;
        
        vector<int> A(N);
        for(int i=0;i<N;i++) A[i]=N-i;
        
        while(R--){
            int X,Y;cin>>X>>Y;
            X--;
            vector<int> B(N);
            for(int i=0;i<Y;i++) B[i]=A[X+i];
            for(int i=0;i<X;i++) B[Y+i]=A[i];
            for(int i=X+Y;i<N;i++) B[i]=A[i];
            
            A=B;
        }
        
        cout<<A[0]<<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 + s;
			count++;
		}
		for(char c = 'A'; c <= 'X'; c++){
			if(count < n) s = c + s;
			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' + 26;
		}
		// cout << s[0] << endl;
		cout << res + 1 << endl;

	}

}

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

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

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

int i, j, n, r, p, c, ans;

int main (){

        while (cin >> n >> r && n != 0 && r != 0){
                vector<int> A(n);
                //auto Xe = A.begin();
                for (i = 0; i < n; i++){
                        A[i] = n - i;
                }
                for (i = 0; i < r; i++){
                        cin >> p >> c;
                        rotate (A.begin(), A.begin() + p - 1, A.begin() + p + c - 1);
                }
                cout << A[0] << endl;
        }

        return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a ; i<b ; i++)
#define dump(x) cout << #x << " = " << x << endl

using namespace std;

int card[50];
int n, r;

void disp(){
	rep(i,0,n) cout << card[i] << " ";
	cout << endl;
	return ;
}

int main(){

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

		rep(i,0,n) card[i] = n - i;
		disp();

		rep(i,0,r){
			int p, c;
			cin >> p >> c;
			int temp[p];

			rep(i,0,p-1) temp[i] = card[i];
			rep(i,0,c) card[i] = card[p-1+i];
			rep(i,0,p-1) card[c+i] = temp[i];

			disp();

		}

		cout << card[0] << endl;

	}
	return 0;
}

C++: #include <iostream>
#include <deque>
#include <queue>
#include <stack>
using namespace std;

int main() {
	int n, r;
	while(cin >> n >> r && (n || r)){
		deque<int> dq;
		for(int i = 1; i <= n; ++i)
			dq.push_front(i);
		
		int p, c;
		for(int i = 0; i < r; ++i){
			cin >> p >> c;
			
			stack<int> ps;
			for(int j = 0; j < p - 1; ++j){
				ps.push(dq.front());
				dq.pop_front();
			}
			
			stack<int> cs;
			for(int j = 0; j < c; ++j){
				cs.push(dq.front());
				dq.pop_front();
			}
			
			for(int j = 0; j < p - 1; ++j){
				dq.push_front(ps.top());
				ps.pop();
			}
			for(int j = 0; j < c; ++j){
				dq.push_front(cs.top());
				cs.pop();
			}
		}
		cout << dq.front() << endl;
	}
	return 0;
}

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

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, r;

    while (true) {
        cin >> n >> r;
        if (n + r == 0) return 0;

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

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

            int b[n];
            for (int j = 0; j < c; ++j) {
                b[j] = a[p - 1 + j];
            }
            for (int j = 0; j < p - 1; ++j) {
                b[c + j] = a[j];
            }
            for (int j = c + p - 1; j < n; j++) {
                b[j] = a[j];
            }

            for (int j = 0; j < n; ++j) {
                a[j] = b[j];
            }
        }
        cout << a[0] << endl;
    }
}

/*
 *
 */