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<iostream>
#include<fstream>
#include<list>

using namespace std;

int main(){

	ifstream fin("in.txt");

	typedef list<int>::iterator Iterator;

	list <int> stock;
	list<int> tmp;

	int n = 0, r = 0;
	int p = 0, c = 0;
	
	while (true){

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

		//?????????
		stock.clear();
		tmp.clear();
		for (int i = 1; i <= n; i++){
			stock.push_back(n - i + 1);
		}

		for (Iterator it = stock.begin(); it != stock.end();){
		//	cout << *it << " ";
			it++;
		}
		//cout << endl;

		//cout << stock.front() << endl;


		for (int i = 0; i < r; i++){

			cin >> p >> c;


			Iterator front = stock.begin();
			for (int i = 0; i < p - 1; i++){
				front++;
			}

			Iterator back = stock.begin();
			for (int i = 0; i < p + c - 1; i++){
				back++;
			}

			tmp.splice(tmp.begin(), stock, front, back);

			stock.splice(stock.begin(), tmp);

			for (Iterator it = stock.begin(); it != stock.end();){
			//	cout << *it << " ";
				it++;
			}
			//cout << endl;
		}

		cout << *stock.begin() << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <string.h>
#include <stdlib.h>

using namespace std;

int n, r, p, c;
int cards[50];
int temp[50];

int main()
{
	while( 1 )
	{
		cin >> n >> r;
		if(n==0 && r==0) break;
		
		for(int i=0; i<n; i++) cards[i] = n-i-1;
		for(int i=0; i<r; i++)
		{
			cin >> p >> c;
			memcpy(&temp[0], &cards[p-1], sizeof(int) * c);
			memcpy(&temp[c], &cards[0], sizeof(int) * (p-1));
			for(int j=0; j<p+c-1; j++) cards[j] = temp[j];
		}
		printf("%d\n", cards[0]+1);
   	}
}

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

using namespace std;

int main(){

	int n,r,c,p,ar[50];
	while(cin>>n>>r){
		if(n==0 && r==0) return 0;
		for(int i=0; i<n; i++) ar[i]=n-i;
		for(int i=0; i<r; i++){
			cin>>p>>c;
			int t1[50],t2[50];
			for(int i=0; i<p-1; i++){
				t1[i] = ar[i];
			}
			for(int i=p-1; i<p+c-1; i++){
				t2[i-p+1] = ar[i];
			}
			for(int i=0; i<c; i++){
				ar[i]=t2[i];
			}
			for(int i=c; i<p+c; i++){
				ar[i]=t1[i-c];
			}
		}
		cout<<ar[0]<<endl;
	}

	return 0;
}

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

struct list{
  int number;
  list *next;
};

void Insertlist(list ** ptr, int newnumber){
  if( *ptr == NULL || (*ptr)->number < newnumber){
    list *newcell;
    newcell = (list *)malloc(sizeof(list));
    newcell->number = newnumber;
    newcell->next = *ptr;
    *ptr = newcell;
  }else{
    Insertlist(&(*ptr)->next, newnumber);
  }
}

int main(){

  int n, r;

  while( cin >> n >> r ){

    if( n == 0 && r == 0) break;

    list *root = NULL;
    for(int i = n ; i > 0 ; i--){
      Insertlist(&root,i);
    }
 
    while( r ){
      int p,c;
      cin >> p >> c;

      list *ptr1 = root, *ptr2 = root,*ptr3,*ptr4;
      
      for(int i = 0 ; i < p-2; i++)
	ptr1 = ptr1->next;
      if(p > 1)
	ptr2 = ptr1->next;
      ptr3 = ptr2;
      for(int i = 0; i < c-1 ; i++)
	ptr3 = ptr3->next;
      ptr4 = ptr3->next;
      
      if(p>1){
	ptr1->next = ptr4;
	ptr3->next = root;
	root = ptr2;
      } 
      r--;
    }
    cout << root->number << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
using namespace std;

#define ll long long
#define MP make_pair

int main(void) {
    int n,r;
    while(1){
        cin>>n>>r;
        if(n==0&&r==0)break;
        vector<int> v(50);
        for (int i = 0; i < n; i++) {
            v[i]=n-i;
        }



        int p,c;
        for (int i = 0; i < r; i++) {
            vector<int> tmp;
            cin>>p>>c;
            copy(v.begin()+p-1,v.begin()+p+c-1,back_inserter(tmp));
            /*for (int l = 0; l < tmp.size(); l++) {
                cout<<"tmp"<<tmp[l]<<"\n";
            }*/
            v.erase(v.begin()+p-1,v.begin()+p+c-1);
            v.insert(v.begin(),tmp.begin(),tmp.begin()+c);
            /* for (int k = 0; k < n; k++) {
                cout<<"v"<<v[k]<<"\n";
            }*/
        }

        cout<<v[0]<<"\n";
    }
    
    
    return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <fstream>
#include <stdint.h>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define FOR(i, l, r) for(int i = l; i < r; i++)
#define RFOR(i, l,r) for(int i= (l)-1; i>= (r) ; i--)

template<typename stl>
void show_vec(const stl& x)
{
    for(auto i : x)
        cerr << i << ' ';
    cerr << '\n';
}

void swap_range(vector<int>& dek, int l, int k)
{
    vector<int> ret;
    int r = l + k;
    /* cerr << "l : r" << l  << ':' << r << '\n'; */
    FOR(i, l, r)
    {
        /* cerr << "i:" << i << ' '; */
        ret.push_back(dek[i]);
    }
    /* cerr << "ret1:: " ; show_vec(ret); */
    REP(i, l)
        ret.push_back(dek[i]);
    /* cerr << "ret2:: " ; show_vec(ret); */
    FOR(i, l+k, dek.size())
        ret.push_back(dek[i]);
    /* cerr << "ret3:: " ; show_vec(ret); */
    dek = ret;
}


int main()
{
    ios::sync_with_stdio(false);
    int n, r;
    while(cin >> n >> r)
    {
        if(n == 0)
            return 0;
        vector<int> dek;
        RFOR(i, n+1, 1)
            dek.push_back(i);
        /* show_vec(dek); */
        REP(i, r)
        {
            int p, c;
            cin >> p >> c;
            swap_range(dek, p-1, c);
            /* show_vec(dek); */
        }
        cout << dek[0] << '\n';
    }
}

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

void show(vector<int> a){
  for(int i=0;i<a.size();i++){
    cout << a[i] << endl;
  }
  cout << endl;
}
int main(){
  while(1){
    int N,R;
    cin >> N >> R;
    if(N==0&&R==0)break;
    vector<int> a;
    for(int i=N;i>=1;i--){
      a.push_back(i);
    }
    for(int i=0;i<R;i++){
      int p,c;
      cin >> p >> c ;
      vector<int> b;
      for(int j=0;j<c;j++){
        b.push_back(a[p-1+j]);
      }
      a.erase(a.begin()+p-1,a.begin()+p-1+c);
      a.insert(a.begin(),b.begin(),b.end());
    }
    cout << a[0] << endl;
  }
}

C++: #include <stdio.h>

int main(){

  int n,r,p,c,i,j;
  int score[51];
  int temp[51];

  scanf("%d%d",&n,&r);

  for(i=1;i<=n;i++){
    score[i]=i;
    temp[i]=i;
  }

  for(i=1;i<=r;i++){
    scanf("%d%d",&p,&c);

    for(j=n-p+1;j>n-p+1-c;j--){
      score[j+p-1]=score[j];
    }
     for(j=n;j>=n-p+1;j--){
     score[j-c]=temp[j];
     }

  }

  printf("%d\n",score[n]);

  return 0;

}