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>

#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::flush;
		//ans[j++] = n1[0];
	}

	/*
	rep(i,j){
		std::cout << ans[i] << std::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 =0 ;j <=p-1;j++){
      Card[l+j] =temp[m++];
    }
  }
  cout <<Card[1]<<endl;
  }
  return 0;
}

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

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;


void show_tower(vector<int> &d) {
    cout << endl;
    for (int _d : d) {
      cout << _d << endl;
    }
    cout << endl;
}


int main() {
  int n, r;
  int s, f, w, k;

  while (cin >> n >> r && n && r) {

    // begin initialize vector
    vector<int> d(n);
    for (int i=0; i<n; i++) {
      d[i] = n-i;
    }
    // end initialize vector

    // begin r times operation
    for (int i=0; i<r; i++) {
      cin >> s >> f;
      s--;

      // begin initialize tmp vector
      vector<int> tmp(n);
      for (int j=0; j<n; j++) {
        tmp[j] = 0;
      }
      // end initialize tmp vector

      // begin copy selected elements
      for (int k=0; k<f; k++) {
        tmp[k] = d[s];
        d[s] = -1;
        s++;
      }
      // end copy selected elements

      // begin find non-zero index
      int k = 0;
      for (;k<n; k++) {
        if (tmp[k] == 0) break;
      }
      // end find non-zero index

      for (int _d : d) {
        if (_d > 0) tmp[k++] = _d;
      }

      d = tmp;
    }
    cout << d[0] << endl;
  }
}

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

using namespace std;

int32_t main()
{
  while(true){
    uint32_t n, r;
    cin >> n >> r;
    if(n == 0) break;

    vector<uint32_t> cards(51, 0);
    for(int32_t i = n-1, j = 1;  i >= 0; i--, j++){
      cards[i] = j;
    }

    for(uint32_t i = 0; i < r; i ++){
      uint32_t p, c;
      cin >> p >> c;
      vector<uint32_t> cs;
      for(uint32_t i = p - 1; i < p - 1 + c; i++){
        cs.push_back(cards[i]);
      }
      for(uint32_t i = 0; i < p - 1; i++){
        cs.push_back(cards[i]);
      }
      for(uint32_t i = p - 1 + c - 1; i < n; i++){
        cs.push_back(cards[i]);
      }

      for(uint32_t i= 0; i < n; i++){
        cards[i] = cs[i];
      }
    }

    cout << cards[0] << endl;
  }
  return 0;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);

int main() {
	int n, r, p, c;
	while (cin >> n >> r&&n&&r) {
		vector<int> vec;
		for (int i = n; i >= 1; i--) {
			vec.emplace_back(i);
		}
		for (int i = 0; i < r; i++) {
			cin >> p >> c;
			for (int j = 0; j < c; j++) {
				vec.insert(vec.begin(),(vec[p + c - 2]));
				vec.pop_back();
			}
		}
		cout << vec[0] << endl;
	}
}

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

int main(){
	while(true){
		int n, r, p, c;
		cin >> n >> r;
		if ((not n) && (not r)) break;
		int card1[n], card2[n];
		for (int i = 0; i < n; ++i){
			card1[i] = n - i;
			card2[i] = n - i;
		}
		for (int i = 0; i < r; ++i){
			cin >> p >> c;
			for (int j = 0; j < n; ++j){
				if (i % 2){
					if (j < c){
						card1[j] = card2[p-1+j];
					}else if(j < c + p - 1){
						card1[j] = card2[j-c];
					}else{
						card1[j] = card2[j];
					}
				}else{
					if (j < c){
						card2[j] = card1[p-1+j];
					}else if(j < c + p - 1){
						card2[j] = card1[j-c];
					}else{
						card2[j] = card1[j];
					}
				}
			}
		}
		if (r%2) cout << card2[0] << endl;
		else cout << card1[0] << endl;
	}
	return 0;
}