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 <numeric>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    while (true) {
        int n;
        int r;
        cin >> n >> r;

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

        vector<int> v(static_cast<size_t>(n));
        iota(begin(v), end(v), 1);
        reverse(begin(v), end(v));
        for (int i = 0; i < r; ++i) {
            int p;
            int c;
            cin >> p >> c;
            vector<int> t;
            copy_n(begin(v) + (p - 1), c, back_inserter(t));
            copy_n(begin(v), p, back_inserter(t));
            copy(begin(v) + (p - 1) + c, end(v), back_inserter(t));
            v = t;
        }
        cout << v[0] << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, R;
	cin >> N >> R;
	while (N != 0) {
		vi V(N);
		REP(i, N) {
			V[i] = N-i;
		}
		REP(i, R) {
			int p, c;
			cin >> p >> c;
			vi New(N);
			int ind = 0;
			FOR(j, p - 1,p - 1 + c) {
				New[ind] = V[j];
				ind++;
			}
			REP(j, p-1) {
				New[ind] = V[j];
				ind++;
			}
			FOR(j,p-1+c,N) {
				New[ind] = V[j];
				ind++;
			}
			V = New;
		}
		cout << V[0] << endl;
		cin >> N >> R;
	}
	return 0;
}

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

int main(){
		
	int n,r,p,c ;
	int x,y;
	int a[51]={},b[51]={},card[51]={};
	
	while(1){
		cin >> n >> r ;
		if( n==0 && r==0 ) break;
		
		for( int i=1 ; i<=n ; i++ ) card[i] = n-i+1 ;
		
		for( int i=0 ; i<r ; i++ ){
			cin >> p >> c ;
			
			for( x=1 ; x<p ; x++ ) a[x] = card[x] ;
			for( y=1 ; y<=c ; y++ ) b[y] = card[x+y-1] ;
			
			swap(a,b);
			
			for( x=1 ; x<=c ; x++ ) card[x] = a[x] ;
			for( y=1 ; y<p ; y++ ) card[x+y-1] = b[y] ;
		}
		
		cout << card[1] << endl ;
	}
	
return 0;
}

C++: #include <vector>
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define revrep(i,n) for(int i = (n)-1;i>=0;i--)
using namespace std;

int main(){
	vector<int> V;
	while(1){
		V.clear();
		int n,r;
		cin >> n >> r;
		if(n == 0 && r == 0){
			break;
		}
		revrep(i,n){
			V.push_back(i + 1);
		}
		// rep(i,V.size()){
		// 		cout << V[i];
		// 	}
		// cout << endl;
		rep(qery,r){
			int p,c;
			cin >> p >> c;
			rotate(begin(V),begin(V)+p-1,begin(V)+p+c-1);
			// rep(i,V.size()){
			// 	cout << V[i];
			// }
			// cout << endl;
		}
		cout << V[0] << endl;
	}
	return 0;
}

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

int main(int argc, char const* argv[])
{
    int n, r;
    while (cin >> n >> r) {
        if (n == 0 and r == 0) break;
        vector<int> cards(n);
        for (int i = 0; i < n; i++) {
            cards[i] = n - i;
        }
        for (int i = 0; i < r; i++) {
            int p, c;
            cin >> p >> c;
            rotate(cards.begin(), cards.begin() + p - 1, cards.begin() + p -1  + c);
        }
        cout << cards[0] << endl;
    }
    return 0;
}

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

int main(){
	int n, r, p, c;
	int card[50], tmp;

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

		for(int i=0; i<n; i++){
			card[i] = n-i;
		}

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

			for(int j=0; j<c; j++){
				tmp = card[p-1+j];
				for(int k=p-2+j; k>=j; k--){
					card[k+1] = card[k];
				}
				card[j] = tmp;
			}
		}
	cout << card[0];
	}
	cout << "\n";
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
int main(){
    int n,r;
    while(cin>>n>>r,n,r){
        int data[50],tmp[50];
        for(int i=0;i<n;i++){
            data[i]=n-i;
            tmp[i]=n-i;
        }
        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]=data[j];
                }else{
                    tmp[j-p+1]=data[j];
                }
            }
            for(int j=0;j<n;j++){
                data[j]=tmp[j];
            }
        }
        cout<<data[0]<<endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265


void f(int n,int r){
  int a[100];
  rep(i,n){
    a[i+1]=n-i;
  }

  rep(i,r){
    int p,c;
    cin>>p>>c;
    int b[100];
    rep(j,p){
      b[j]=a[j+1];
    }
    rep(j,c){
      a[j+1]=a[p+j];
    }
    rep(j,p){
      a[j+c+1]=b[j];
    }
  }

  cout<<a[1]<<endl;

}

int main(){
  while(1){
    int n,r;
    cin>>n>>r;
    if(n==0) break;
    f(n,r);
  }

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stdlib.h>
using namespace std;
int N, R, p, c;
int main() {
  while (cin >> N >> R && N){
    vector<int> A(N,0);
    int i;
    cout << "[";
    for(i=0;i<N;i++){
      A[i]=N-i;
      if (i<N-1)
        cout << A[i] << ",";
      else
        cout << A[i];
    }
    cout << "]" << endl;
    for(i=0;i<R;++i){
      cin >> p >> c;
      if (p==0){
        cout << "Incorrect input" << endl;
        exit(1);
      }
      rotate(A.begin(),A.begin()+p-1,A.begin()+p+c-1);
    }
    cout << A[0] << endl;
  }
}