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 <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

using namespace std;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
typedef complex<int> P;
typedef pair<int,int> pii;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
template <class F, class T> void convert(const F &f, T &t){	stringstream ss; ss << f; ss >> t;}


bool solve(){
	int n, r;
	cin>> n>> r;
	if(n==0 && r==0) return false;
	
	int crr = 0, nex = 1;
	vector<vector<int> > a(2, vector<int>(n));
	for(int i=0;i<n;i++) a[crr][i] = n-i;
	
	for(int i=0;i<r;i++){
		int p, c;
		cin>> p>> c;
		for(int j=0;j<n;j++){
			if(j < c){
				a[nex][j] = a[crr][j+p-1];
			}else if(j < c + p - 1){
				a[nex][j] = a[crr][j-c];
			}else{
				a[nex][j] = a[crr][j];
			}
		}
		swap(crr, nex);
//		for(int k=0;k<n;k++) cout<< a[crr][k]<<" "; cout<< endl;
	}
	
	cout<< a[crr][0]<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed); cout.precision(10);
	while(solve());
	return 0;
}

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

using namespace std;

int main()
{
    int n, r;
    while (cin >> n >> r, n | r)
    {
        vector<int> deck(n);
        for (int i = 1; i <= n; ++i)
        {
            deck[n - i] = i;
        }
        for (int i = 0; i < r; ++i)
        {
            int p, c;
            cin >> p >> c;

            vector<int> buf(deck.begin(), deck.begin() + p - 1);
            copy(deck.begin() + p - 1, (deck.begin() + p - 1) + c, deck.begin());
            copy(buf.begin(), buf.end(), deck.begin() + c);
        }
        cout << deck[0] << endl;
    }
    return 0;
}

C++: //#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <utility>
using namespace std;
#define INF 100000005
#define MAX 200005

int a[100];

int solve(int p, int c, int n){
	int x[100], y[100], xx = 0, yy = 0;
	for(int i = n;1;i--){
		if(n-p < i)x[xx++] = a[i];
		else if(n-p-c < i)y[yy++] = a[i];
		else break;
	}
	for(int i = 0;i < n;i++){
		if(n-p-c >= i);
		else if(n-c > i)a[i] = x[--xx];
		else a[i] = y[--yy];
	}
	return 0;
}

int main(){
	int n, r, p, c;
	while(cin >> n >> r, n){
		for(int i = 0;i < n;i++)a[i] = i+1;
		for(int i = 0;i < r;i++){
			cin >> p >> c;
			solve(p, c, n);
		}
		cout << a[n-1] << endl;
	}
	return 0;
}

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

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

void Insertlist(list **ptr, int newnumber);

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<algorithm>
#include<vector>
#include<deque>
using namespace std;

int main(){
	int n,r;
	while(scanf("%d%d",&n,&r),n){
		deque< int > DQ;
		for(int i = 0; i < n; i++){
			DQ.push_back(n-i);
		}
		for(int i = 0; i < r; i++){
			int p,c;
			scanf("%d%d",&p,&c);
			p--;c;
			vector < int > sub;
			for(int j = p; j < p+c; j++){
				sub.push_back(DQ[j]);
				DQ[j] = 0;
			}
			deque < int > :: iterator it = remove(DQ.begin(),DQ.end(),0);
			DQ.erase(it,DQ.end());
			for(int j = 0; j < sub.size(); j++){
				DQ.push_front(sub[sub.size()-1-j]);
			}
		}
		printf("%d\n",DQ[0]);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)
const double eps = 1e-10;
const double pi = acos(-1.0);
const double inf = (int)1e8;

int main(){
  int n,r;
  while(cin>>n>>r&&n+r!=0){
    list<int> fuda;
    rep(i,n){
      fuda.pb(n-i);
    }
    int p,c;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      rep(j,c){
        auto tmp = fuda.begin();
        rep(l,p+c-2){
          tmp++;
        }
        rep(l,c){
          fuda.push_front(*tmp);
          fuda.erase(tmp);
        }
      }
    }
    cout << fuda.front() << endl;
  }
}

C++: #include<stdio.h>

int main(void)
{
  int i,j;
  int n,r;
  int p,c;
  int h[50],tmp[50];


  while(1){
      scanf("%d %d",&n,&r);
      if(!n && !r){break;}

      for(i=0;i<n;i++)h[i] = n-i;
 
      for(i=0;i<r;i++){
	scanf("%d %d",&p,&c);
	p--;
	for(j=0;j<c;j++)tmp[j] = h[j+p];

	for(j=p-1;j>=0;j--)h[j+c] = h[j];

	for(j=0;j<c;j++)h[j] = tmp[j];
      }

      printf("%d\n",h[0]);
    }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	while(true){
		int n,r;	cin>>n>>r;
		if(n==0)	return 0;
		vector<int> a;
		for(int i=n;i>0;i--)	a.push_back(i);
		while(r--){
			int p,c;	cin>>p>>c;
			vector<int> b(n);
			for(int i=0;i<p-1;i++)	b[c+i]=a[i];
			for(int i=0;i<c;i++)	b[i]=a[p-1+i];
			for(int i=p+c-1;i<n;i++)	b[i]=a[i];
			a=b;
		}
		cout<<a[0]<<endl;
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main() {
    while (1) {
        int n, r; cin >> n >> r;
        if (n == 0 && r == 0) break;
        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;
            rotate(a, a + (p - 1), a + (p - 1) + c);
            /*
            for (int j = 0; j < n; ++j) {
                cout << a[j] << " ";
                if (j == n - 1) cout << endl;
            }
             */
        }
        cout << a[0] << endl;
    }
    return 0;
}