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<list>
using namespace std;

int main()
{
  list<int> l,ll;
  list<int>::iterator start,end;
  int n,r,i,p,c;
  while(cin>>n>>r,n||r){
    l.clear();
    for(i=1;i<=n;i++)l.push_front(i);
    while(r-->0){
      cin>>p>>c;
      start=end=l.begin();
      advance(start,p-1);
      advance(end,p-1+c);
      ll.clear();
      ll.splice(ll.begin(),l,start,end);
      l.splice(l.begin(),ll);
    }
    cout<<*l.begin()<<endl;
  }
}

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 reprb(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;
vector<int> cb,ca,a;

int main(int argc,char * argv[])
{
	int n,r,c,p,cnt=0;
	while(true)
	{
		cin>>n>>r;
		if(n==0&&r==0)	break;
		rep(i,n)	cb.pb(n-i);
		rep(i,r){
			cin>>c>>p;
			reps(j,p,p+c){
				ca.pb(cb[i]);//c
			}
			rep(j,p){
				ca.pb(cb[i]);//p-1
			}
			reps(j,p+c-1,n){
				ca.pb(cb[i]);
			}
			if(i==r-1)	{
				a.pb(cb[0]);
				cnt++;
			}

		}

	}
	rep(i,cnt){
		cout<<a[i]-1<<endl;
	}

	return 0;
}

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

int main(){
	int n,r;
	while(cin >> n >> r){
		if(n==0 && r==0) break;
		int card[51];
		for(int i=0; i<n; i++){
			card[i] = n-i;
		}

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

			vector<int> change;
			// Cツづ個閉板閉ェ
			for(int i=p-1; i<p-1+c; i++){
				change.push_back(card[i]);
			}
			
			// P-1ツづ個閉板閉ェ
			for(int i=0; i<p-1; i++){
				change.push_back(card[i]);
			}
			/*
			for(int i=p-1+c; i<n; i++){
				change.push_back(card[i]);
			}
			*/
			int count=0;
			vector<int>::iterator it = change.begin();
			while(it!=change.end()){
				card[count] = *it;
				count++;
				it++;
			}
		}
		cout << card[0] << endl;
	}
	return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   int n, r;
   while (1) {
      // 初期化
      cin >> n >> r;
      vec<int> v(n);
      rep (i, n) { v[i] = n-i; }
      if (n == 0 && r == 0) return 0;

      // 実体
      while (r--) {
         int p, c;
         cin >> p >> c;
         vec<int> next;
         p--;
         repp (i, p, p+c) {
            next.push_back(v[i]);
         }
         rep (i, n) {
            if (i >= p && i < p+c) continue;
            next.push_back(v[i]);
         }

         v = next;
      }
      cout << v[0] << endl;
   }

   return 0;
}

C++: #include <bits/stdc++.h>

#define var auto
#define long long long
#define ll long
#define Max std::max
#define Min std::min
#define Abs std::abs

void Solve();

using namespace std;

int main() {
    while (true) {
        Solve();
    }
}

void Solve() {
    int n, r;
    cin >> n >> r;
    if (n == 0 && r == 0) exit(0);
    var pile = new vector<int>(n);
    iota(pile->begin(), pile->end(), 1);
    reverse(pile->begin(), pile->end());
    for (int i = 0; i < r; ++i) {
        var newPile = new vector<int>();
        int p, c;
        cin >> p >> c;
        for (int j = p - 1; j < p + c - 1; ++j) {
            newPile->push_back((*pile)[j]);
        }
        for (int j = 0; j < p - 1; ++j) {
            newPile->push_back((*pile)[j]);
        }
        for (int j = p + c - 1; j < n; ++j) {
            newPile->push_back((*pile)[j]);
        }
        pile = newPile;
    }
    cout << (*pile)[0] << endl;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>

#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,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, r;
	while (1) {
		cin >> n >> r;
		if (!n) break;
		vector<int> card(n);
		REP(i, n) {
			card[i] = n - i;
		}
		REP(i, r) {
			int p, c;
			cin >> p >> c;
			int *tmp = new int[c];
			REP(j, c) tmp[j] = card[p - 1 + j];
			RREP(j,p-1 ) card[j+c] = card[j];
			REP(j, c) card[j] = tmp[j];
		}
		cout << card[0] << endl;


	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

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

C++: #include<bits/stdc++.h>

using namespace std;

int main(){
	
	while(1){
		
		int n,count;
		
		cin >> n >> count;
		
		if(n==0 && count==0)
			return 0;
		
		int d[n];
		
		for(int i=0;i<n;i++)
			d[i] = n-i;
		
		for(int i=0;i<count;i++){
			int p,c;
			
			cin >> p >> c;
			
			int t[n];
			
			int j;
			for(j=0;j<c;j++){
				t[j]=d[p-1+j];
			}
			for(;j<c+p-1;j++){
				t[j]=d[j-c];
			}
			for(;j<n;j++){
				t[j]=d[j];
			}
			for(j=0;j<n;j++){
				d[j]=t[j];
			}
		}
		cout << d[0] <<endl;
		
	}
	return 0;
}