Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		n, _ := strconv.Atoi(chunks[0])
		r, _ := strconv.Atoi(chunks[1])
		cards := make([]int, n, n)
		for i := 0; i < n; i++ {
			cards[i] = n - i
		}
		for i := 0; i < r; i++ {
			sc.Scan()
			chunks := strings.Split(sc.Text(), " ")
			p, _ := strconv.Atoi(chunks[0])
			c, _ := strconv.Atoi(chunks[1])
			block := make([]int, c, c)
			for j := 0; j < c; j++ {
				block[j] = cards[p+j-1]
			}
			for j := p - 2; j >= 0; j-- {
				cards[j+c] = cards[j]
			}
			for j := 0; j < c; j++ {
				cards[j] = block[j]
			}
		}
		fmt.Println(cards[0])
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main() {
	int n, r, a, b, temp, s=0, t=0;
	while(1){
		cin >> n >> r;
		int p[n];
		if(n==0 && r==0) break;
		for(int i=0; i<n; i++){
			p[i]=n-i;
		}
		for(int i=0;i<r; i++){
			cin >> a >> b;
			for(int j=0; j<b; j++){	
				for(int k=a-1+t;k>s;k--){
					temp=p[k];
					p[k]=p[k-1];
					p[k-1]=temp;
				}
				s++;
				t++;
			}
			s=0;
			t=0;
		}
		cout << p[0] << endl;
	}
}

C++: #include<cstdio>
int main(void){
  int n, r, p, c;
  int card[64], w[64];
  for( ; ; ){
    scanf("%d %d", &n, &r);
    if(!(n + r)) break;
    for(int i = 1;i <= n; i++) card[n - (i - 1)] = i;
    for(int j = 0;j < r; j++){
      scanf("%d %d", &p, &c);
      for(int i = 1;i <= n; i++) w[i] = card[i];
      for(int i = c + 1;i < c + p; i++) card[i] = w[i - c];
      for(int i = 1;i <= c; i++) card[i] = w[i + p - 1];
    }
    printf("%d\n", card[1]);
  }
}

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 repb(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;

int main(){
	int n,p,c,r;
	while(true)
	{
		cin>>n>>r;
		if(n==0)	return 0;
		int b[50];
		rep(i,n){
			b[i]=n-i;
		}

		rep(s,r){
			int a[50],j;
			cin>>p>>c;
			for(j=0;j<c;j++){
				a[j]=b[p+j-1];
			}
			for(;j<p+c-1;j++){
				a[j]=b[j-c];
			}
			for(;j<n;j++){
				a[j]=b[j];
			}
			rep(t,n){
				b[t]=a[t];
			}
		}
		cout<<b[0]<<endl;
	}

	return 0;
}

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;
}