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

int main(){
    int N,r;
    vector<int> ans;
    while(cin>>N>>r,N != 0 && r != 0){

        stack<int> card;
        for(int i = 1;i <= N;i++) card.push(i);

        for(int i=0;i<r;i++){
            int P,C;
            stack<int> p;
            stack<int> c;
            cin>>P>>C;
            
            for(int i=0;i<P-1;i++){
                p.push(card.top());
                card.pop();
            }

            for(int i=0;i<C;i++){
                c.push(card.top());
                card.pop();
            }

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

            while(!c.empty()){
                card.push(c.top());
                c.pop();
            }
            
        }
        ans.push_back(card.top());
    }
    for(int i : ans) cout<<i<<endl;
}

C++: #include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define REEP(i, N) for(ll i = N - 1; i >= 0; --i)
#define FOR(i,m,n) for(ll i = m; i < n; ++i)
#define RFOR(i,m,n) for(ll i = n - 1; i >= m; --i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define PB push_back
#define KIRIAGE(a, b) a += (b - a % b) % b // a ??? b ????????°????????§?¢???????
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;} // a / b ??\??????????°???´??°
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
int main(void) {
    while(true) {
        int n, r;
        cin>>n>>r;
        vector<ll> card(n);
        REP(i, n) {
            card[i] = n - i;
        }
        if(n==0&&r==0) return 0;
        REP(i, r) {
            int p, c;
            cin>>p>>c;
            vector<ll> hoge(p - 1);
            REP(i, p - 1) hoge[i] = card[i];
            REP(i, c) card[i] = card[p - 1 + i];
            REP(i, p - 1) card[c + i] = hoge[i];
        }
        cout<<card[0]<<endl;
    }
}

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

int main() {
  int n, r;

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

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n,r;
	while(cin>>n>>r,r){
		int cards[60],i;
		for(i=0;i<60;i++)cards[i]=i;
		for(i=0;i<r;i++){
			int a,b;
			cin>>a>>b;
			a--;
			int j;
			int c[60];
			for(j=0;j<60;j++){
				if(j<b){
					c[j]=cards[a+j];
				}else if(j<a+b){
					c[j]=cards[j-b];
				}else{
					c[j]=j;
				}
			}
			for(j=0;j<60;j++){
				cards[j]=c[j];
//cout<<cards[j]<<endl;
			}
//cout<<endl;
		}
		cout<<n-cards[0]<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
int main(){
  int n,r,p,c,i,j,k,l,nh[51],s[51];
  while(1){
    scanf("%d%d",&n,&r);
    if(n==0&&r==0) break;
 
    for(i=n;i>=1;i--){
      nh[n-i+1]=i;
    }
  
    for(i=0;i<r;i++){
      scanf("%d%d",&p,&c);
      for(j=p;j<=p+c-1;j++){
        s[j]=nh[j];
      }
    l=0;
      for(j=1;j<=c;j++){
    for(k=p-1+l;k>=1+l;k--){
          nh[k+1]=nh[k];
    }
        l++;
      }
     
      for(j=p;j<=p+c-1;j++){
        nh[j-p+1]=s[j];
      }
    }
 
    printf("%d\n",nh[1]);
  }
    return 0;
}

C++: #include <iostream>

using namespace std;

void cut(int[],int,int);

int main(void){
	int p,c;

	for(int n,r;cin >> n >> r,n||r;){
		int card[n];
		for(int i=0;i<n;i++)
			card[i]=n-i;

		for(int i=0;i<r;i++){
			cin >> p >> c;
			if(p!=1)
				cut(card,p,c);
		}

		cout << card[0] << endl;
	}

	return 0;
}

void cut(int card[],int p,int c){
	int tmp[c];

	for(int i=0;i<c;i++)
		tmp[i]=card[p-1+i];

	for(int i=1;i<=p;i++)
		card[p+c-i]=card[p-i];

	for(int i=0;i<c;i++)
		card[i]=tmp[i];
}

C++: #include <iostream>
#include <cstdio>
#include <queue>
#define INF 1e+18
#define int long long
using namespace std;

signed main(){
	int n,r;
	while(cin >> n >> r,n){
		int card[50];
		for(int i = 0;i < n;i++) card[i] = n - i;
		queue<int> que;
		for(int i = 0;i < r;i++){
			int a,b;
			cin >> a >> b;
			for(int j = 0;j < a - 1;j++) que.push(card[j]);
			for(int j = a - 1;j < a + b - 1;j++) card[j - a + 1] = card[j];
			for(int j = b;j < a + b - 1;j++){
				 card[j] = que.front();
				 que.pop();
			}
		}
		cout << card[0] << endl;
	}
	return 0;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int Card[60];
int temp[60];
int main()
{
  int n,r;
  while(cin >>n>>r,n||r){
  int k = n;
  for(int i = 1; i <=n;i++){
    Card[i] =k--;
  }
  int p,c;
  for(int i = 0;i <r;i++){
    cin>>p>>c;
    int l = 1;
    int m = 1;
    for(int j = 1; j <=p+c-1;j++){
      temp[j] = Card[j];
    }for(int j = p;j <=p+c-1;j++){
      Card[l++] =Card[j];
    }for(int j =l ;j <=p;j++){
      Card[j] =temp[m++];
    }
  }
  cout <<Card[1]<<endl;
  }
  return 0;
}