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>

using namespace std;

vector<int> cut(vector<int>& card, int ft, int noc)
{
	vector<int>::iterator itr;
	for(itr = card.begin(); itr != card.end(); ++itr){
		if(*itr < ft){
			*itr += noc;
		}else if(*itr < ft + noc ){
			*itr -= ft - 1;
		}
	}
	//for(itr = card.begin(); itr != card.end(); ++itr)
		//cout << *itr <<endl;
	//cout << endl;
	return card;
}

int main(void)
{
	int num, cut_num, top;
	vector<int>::iterator itr;

	while(1){
		cin >> num >> cut_num;
		if(num == 0 && cut_num == 0){
			break;
		}

		vector<int> card;
		for(int i = 0; i < num; i++){
			card.push_back(i + 1);
		}

		for(int i = 0; i < cut_num; i++){
			int from_top, num_of_cards;
			cin >> from_top >> num_of_cards;
			card = cut(card, from_top, num_of_cards);
		}

		itr = card.begin();
		for(int i = 0; i < num; i++){
			if(*itr == 1){
				top = i;
				break;
			}
			itr += 1;
		}
		cout << num - top << endl;

	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>

#define rep(i, j) for(int i = 0; i < j; i++)

using namespace std;

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

	while (1)
	{
		int n = 0, r = 0; cin >> n >> r;
		if (n == 0 && r == 0) { return 0; }
		int p = 0, c = 0;
		vector<int> bef(n + 5);
		vector<int> aft(n + 5);
		rep(i, n) 
		{
			bef[i] = n - i;
			aft[i] = n - i;
		}
		rep(i, r)
		{
			cin >> p >> c;
			rep(j, p - 1){	aft[c + j] = bef[j];	}
			rep(j, c)	{	aft[j] = bef[p - 1 + j];	}
			bef = aft;
		}
		printf("%d\n", bef[0]);
	}
	return 0;
}

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

int main(void){
  while(true){
    int n, r;
    cin >> n >> r;
    if(n == 0)
      break;

    vector<int> hana(n);
    for(int i=0; i<n; i++)
      hana[i] = n-i;

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

      vector<int> temp(p-1);
      for(int j=0; j<p-1; j++)
	temp[j] = hana[j];
      for(int j=0; j<c; j++)
	hana[j] = hana[j+p-1];
      for(int j=0; j<p-1; j++)
	hana[j+c] = temp[j];
    }

    cout << hana[0] << endl;
  }
  
  return 0;
}

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

using namespace std;

vector<int> Shuffle(int, int, vector<int>);

int main(){
  int i, n, r, p, c;
  vector<int> data;

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

    for(i=n; i>0; --i)
      data.push_back(i);

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

    cout << data[0] << endl;
    data.clear();
  }

  return 0;
}

vector<int> Shuffle(int p, int c, vector<int> x){
  vector<int> y;

  copy(x.begin()+p-1, x.begin()+p+c-1, back_inserter(y));
  copy(x.begin(), x.begin()+p-1, back_inserter(y));
  copy(x.begin()+p+c-1, x.end(), back_inserter(y));

  return y;
}

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

int main() {
  int n, r;
  while (cin >> n >> r, n) {
    auto v = vector<int>(n);
    iota(begin(v), end(v), 1);
    reverse(begin(v), end(v));

    auto tmp = v;
    for (int i = 0; i < r; ++i) {
      int p, c; cin >> p >> c;
      for (int i = 0; i < c; ++i) tmp[i] = v[i + p - 1];
      for (int i = 0; i < p - 1; ++i) tmp[i + c] = v[i];
      v = tmp;
    }
    cout << v[0] << endl;
  }
  return 0;
}

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

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)

typedef long long ll;


int main(void) {
    int n,r;
    while (cin>>n>>r && n){
        vector<int> a(n);
        REP(i,n){
            a[i] = i+1;
        }
        while(r--){
            int p,c;
            cin >> p >> c;
            REP(i,c){
                int k=a[n-p-c+1];
                a.erase(a.begin()+n-p-c+1);
                a.push_back(k);
            }
        }
        cout << a[n-1] << endl;
    }
    
    return 0;
}

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

using namespace std;

int n,r;

int c1[1001],c2[1001];

int main(void){
	while(1){
		scanf("%d%d",&n,&r);
		if(n==0)break;
		for(int i=0;i<n;i++)c1[i]=c2[i]=n-i;
		for(int i=0;i<r;i++){
			int p,c;
			scanf("%d%d",&p,&c);
			for(int j=0;j<c;j++)c2[j]=c1[j+p-1];
			for(int j=c;j<c+p-1;j++)c2[j]=c1[j-c];
			for(int j=c+p;j<n;j++)c2[j]=c1[j];
			for(int j=0;j<n;j++){
				c1[j]=c2[j];
				//printf("%d\n",c1[j]);
			}
		}
		printf("%d\n",c1[0]);
	}
	return 0;
}

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

int main(){
	int n,r;
	while(cin >> n >> r, n, r){
		int huda[50], tmp[50];
		for(int i=0; i<n; i++){
			huda[i]	= n-i;
			tmp[i] = n-1;
		}
		for(int i=0; i<r; i++){
			int p,c;
			cin >> p >> c;
			for(int j=0; j < p+c-1; j++){
				if(j<p-1){
					tmp[j+c] = huda[j];
				}else{
					tmp[j-p+1] = huda[j];
				}
			}
			for(int j=0; j<n; j++){
				huda[j] = tmp[j];	
			}
		}
		cout << huda[0] << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;

int main(void) {
	int N, R;
	while (cin >> N >> R, N) {
		if (N == 1){
			cout << 1 << endl;
			continue;
		}
		
		stack<int> yama;
		for (int i = 1; i <= N; i++) {
			yama.push(i);
		}

		for (int i = 0; i < R; i++) {
			stack<int> p;
			stack<int> c;
			int begin, size;
			cin >> begin >> size;

			for (int j = 0; j < begin - 1; j++) {
				p.push( yama.top() );
				yama.pop();
			}
			for (int j = 0; j < size; j++) {
				c.push ( yama.top() );
				yama.pop();
			}

			while (!p.empty()) {
				yama.push( p.top() );
				p.pop();
			}
			while (!c.empty()) {
				yama.push( c.top() );
				c.pop();
			}
		}

		cout << yama.top() << endl;
	}

	return 0;
}

C++: #include <cstdio>

int main()
{
    int deck[50] = {}, tam[50] = {}, num, times, p, c;

    while (1)
    {
        scanf("%d %d", &num, &times);
        if (num == 0 && times == 0)
        {
            break;
        }
        for (int i = 0; i < num; i++)
        {
            deck[i] = num - i;
        }

        for (int i = 0; i < times; i++)
        {
            scanf("%d %d", &p, &c);
            for (int j = 0; j < p - 1; j++)
            {
                tam[j] = deck[j];
            }
            for (int j = 0; j < c; j++)
            {
                deck[j] = deck[j + p - 1];
            }
            for (int j = 0; j < p - 1; j++)
            {
                deck[c + j] = tam[j];
            }
        }
        printf("%d\n", deck[0]);
    }
}

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

int main(){

  while(1){
    int card,x;
    cin >> card >> x;
    if(card==0 && x == 0) break;
    int p[100];
    for(int i = 1; i <= card;i++){
      p[card-i+1] = i;
    } 
    for(int i = 1;i <= card;i++){
      //   cout << p[i] << endl;
    }
    for(int i = 0; i < x;i++){
      int a,b;
      cin >> a >> b;
      int tmp[200]={};
      for(int j = 1 ; j < a ; j++){
	tmp[j]= p[j];
      } 
      for(int j = 1; j <= b; j++){
	p[j] = p[a+j-1];
      }
      for(int j = b+1; j <= a+b-1; j++){
	p[j] = tmp[j-b];
      }
    }
    for(int i = 1;i <= card;i++){
      //  cout << p[i] << endl;
    }
    cout << p[1] << endl;

  }
  return 0;
}