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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1129&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

int n,r;

ll solve(){
    vector<int> s(n);
    iota(s.begin(),s.end(),1); reverse(s.begin(), s.end());
    for(int i = 0; i < r;i++){
        int a,b; cin >> a >> b; a--;
        vector<int> s1(s.begin()+a,s.begin()+a+b),s2(s.begin(),s.begin()+a),s3(s.begin()+a+b,s.end());
        s.clear();
        for(auto v:s1) s.push_back(v);
        for(auto v:s2) s.push_back(v);
        for(auto v:s3) s.push_back(v);
    }
    return *s.begin();
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> n >> r,n|r){
        cout << solve() << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>

int testcase_ends() {
  size_t n, r;
  scanf("%zu %zu", &n, &r);
  if (n == 0 && r == 0) return 1;

  std::vector<int> a(n);
  std::iota(a.begin(), a.end(), 1);
  std::reverse(a.begin(), a.end());

  for (size_t i = 0; i < r; ++i) {
    size_t p, c;
    scanf("%zu %zu", &p, &c);
    --p;
    std::vector<int> a0(a.begin()+p, a.begin()+p+c);
    std::vector<int> a1(a.begin(), a.begin()+p);
    a0.insert(a0.end(), a1.begin(), a1.end());
    for (size_t j = 0; j < a0.size(); ++j) a[j] = a0[j];
  }
  printf("%d\n", a[0]);
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}

C++: #include <iostream>

#define rep(i, m) for(int i=0; i<m; i++)

int main(void){

	int n, r;		//山の枚数、回数
	int p, c;		//上からの何枚目、枚数
	int n1[50];	//山
	int temp[50];	//一時的に保存しておく
	int ans[50];	//答えを保存しておく
	int j=0;		//答えを格納する時に使う

	while(std::cin >> n >> r, n || r){		//n,rを取得０、０でなければループ

		rep(i,n){
			n1[i] = n-i;						//n1[n] = {n,n-1,n-2,.........,1}
		}

		rep(i,r){

			std::cin >> p >> c;				//p,cを取得
			rep(i, c){
				temp[i] = n1[p-1+i];
			}
			rep(i, p-1){
				n1[p-1-i+c] = n1[p-1-i];
			}

			rep(i,c){
				n1[i] = temp[i];
			}
		}
		std::cout << n1[0] << std::endl;
		//ans[j++] = n1[0];
	}

	/*
	rep(i,j){
		std::cout << ans[i] << std::endl;
	}
	*/
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, r, p, c;
V v;

int main(){
	while (cin >> n >> r&&n + r){
		REP(i, n){
			v.push_back(n - i);
		}
		REP(i, r){
			cin >> p >> c;
			V t;
			REP(i, c){
				t.push_back(v[p - 1 + i]);
			}
			REP(i, p - 1){
				t.push_back(v[i]);
			}
			FOR(i, p - 1 + c, n){
				t.push_back(v[i]);
			}
			cout << endl;
			v = t;
		}
		cout << v[0] << endl;
		v.clear();
	}
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int t[55][55];
int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	while(cin>>n>>m){
		if(!n)break;
		memset(t,0,sizeof(t));
		for(i=0;i<n;i++)t[0][i]=n-i;
		for(i=0;i<m;i++){
			cin>>a>>b;
			for(j=0;j<n;j++){
				if(j<b)t[i+1][j]=t[i][a+j-1];
				else if(j<a+b-1)t[i+1][j]=t[i][j-b];
				else t[i+1][j]=t[i][j];
			}
		}
		cout<<t[m][0]<<endl;
	}
}

C++: #include<iostream>
using namespace std;
int n,r,a,b;
int t[100];
int u[100],size;
int main(){
  while(cin>>n>>r&&n&&r){
    for(int i=0;i<n;i++)t[i]=n-i;
    for(int i=0;i<r;i++){
      cin>>a>>b;
      for(int j=0;j<b;j++)u[j]=t[j+a-1];
      for(int j=a-2;j>=0;j--)t[j+b]=t[j];
      for(int j=0;j<b;j++)t[j]=u[j];
    }
    cout<<t[0]<<endl;
  }
  return 0;
}

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

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

		if (n == 0 && r == 0) break;
		vector<int> cards;
		for (int i = 1; i <= n; i++) {
			cards.push_back(i);
		}

		for (; r > 0; r--) {
			cin >> p >> c;

			p = n - p - c + 1;
			for (; c > 0; c--) {
				cards.push_back(cards[p]);
				cards.erase(cards.begin() + p);
			}
		}
		cout << cards.back() << '\n';
	}
	return 0;

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#define rep(i,l,n) for(int i=(l);i<(n);i++)

int n,r,i,card[55],change[55]={0};

void shuffle(int p,int c){
	rep(i,1,c+1) change[i]=card[p-1+i];
	rep(i,1,p) change[c+i]=card[i];
	rep(i,1,c+p) card[i]=change[i];
}
int main(void){
	int c,p;
	while(1){
		r=0;
		scanf("%d %d",&n,&r);
		//printf("%d %d\n",n,r);
		if(n==0 && r==0) break;
		rep(i,1,n+1) card[i]=n+1-i;
		rep(i,0,r){
			scanf("%d %d",&p,&c);
			//printf("pc %d %d %d\n",r,p,c);
			shuffle(p,c);
		}
		printf("%d\n",card[1]);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


void printv(vector<int> v) {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i] << " ";
	}
	cout << endl;
}
int main() {
	
	while(1) {
		int n,r; cin >> n >> r;
		if(n + r == 0) {
			break;
		}

		vector<int> H(n,0);
		for (int i = 0; i < n; i++) {
			H[i] = n - i;
		}

		for (int j = 0; j < r; j++) {
			vector<int> a;
			vector<int> b;
			int p,c; cin >> p >> c;
			for (int i = 0; i < p-1; i++) {
				a.push_back(H[i]);
			}
			//cout << "a" << endl;
			//printv(a);
			for (int i = p - 1; i < p - 1 + c; i++) {
				b.push_back(H[i]);
			}
			//cout << "b" << endl;
			//printv(b);
		
			for (int i = 0; i < c; i++) {
				H[i] = b[i];
			}
			//cout << "H1" << endl;
			//printv(H);
			for (int i = 0; i < p - 1; i++) {
				H[c + i] = a[i];
			}
			//cout << "H2" << endl;
			//printv(H);
		}
		cout << H[0] << endl;
	}


	return 0;
}