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 <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1e-8

int v[2][55];

int main(){
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0)return 0;
		REP(i,n)v[0][i]=n-i;
		REP(i,m){
			int p,c;
			cin>>p>>c;
			p--;
			copy(&v[i%2][0], &v[i%2][n], &v[(i+1)%2][0]);
			copy(&v[i%2][0], &v[i%2][p], &v[(i+1)%2][c]);
			copy(&v[i%2][p], &v[i%2][p+c], &v[(i+1)%2][0]);
		}
		cout << v[m%2][0] << endl;
	}
}

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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, r;
  while (cin >> n >> r) {
    if (n == 0 && r == 0) break;
    vector<P> num(n);
    rep(i, n) {
      num[i].first = i + 1;
      num[i].second = n - i;
    }

    rep(i, r) {
      int p, c;
      cin >> p >> c;
      int tmp = 1;
      rep(i, p + c - 1) {
        if (i < p - 1) {
          num[i].first += c;
        } else {
          num[i].first = tmp;
          tmp++;
        }
      }
      sort(all(num));
    }

    cout << num[0].second << "\n";
  }

  return 0;
}

C++: #include <iostream>
using namespace std;
 
int n, r, p, c;
int cards[64];
 
void init() {
    for(int i = 0; i < n; i++)
        cards[i] = n - i;
}
 
bool input() {
    cin >> n >> r;
    if(!n && !r)
        return false;
    return true;
}
 
void shuffle() {
    int tmp[64];
    
    // c 個分の要素をtmpに格納
    for(int i = 0; i < c; i++)
        tmp[i] = cards[p - 1 + i];
    // p-1 個分の要素を c 個分ずらす
    for(int i = 0; i < p - 1; i++)
        cards[p - 2 - i + c] = cards[p - 2 - i];
    // 先頭に c 個分の要素をつめる
    for(int i = 0; i < c; i++)
        cards[i] = tmp[i];
}
 
int solve() {
    for(int i = 0; i < r; i++) {
        cin >> p >> c;
        shuffle();
        
        for(int j = 0; j < n; j++)
            cout << cards[j] << " ";
        cout << endl;
    }
    return cards[0];
}
 
int main() {
    while(input()) {
        init();
        cout << solve() << endl;
    }
    return 0;
}

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

int main(){
    int n,r,p,c;
    vector<int> cards;

    while(cin >> n >> r, n&&r){
        cards.clear();
        for(int i = 0; i < n; i++){
            cards.push_back(n - 1);
        }
        while(r--){
            cin >> p >> c;
            vector<int> cpCards = cards;
            int pos = 0;
            for(int i = p - 1; i < p - 1 + c; i++){
                cards[pos] = cpCards[i];
                pos++;
            }
            for(int i = 0; i < p - 1; i++){
                cards[pos] = cpCards[i];
                pos++;
            }
        }
        cout << cards.front() << endl;
    } 
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int main(){
  int n, r;
  while(scanf("%d%d", &n, &r) && n && r){
    vector<int>a(n);
    rep(i, n) a[i] = n-i;
    int p, c;
    //    rep(i, n) printf("%d ", a[i]); puts("");
    while(r--){
      scanf("%d%d", &p, &c);p--;
      vector<int>tmp(c);
      REP(i, p, p + c) tmp[i-p] = a[i];
      for(int i = p; i > 0; --i) a[i] = a[i-c];
      rep(i, c) a[i] = tmp[i];
      //      rep(i, n) printf("%d ", a[i]); puts("");
      //      rep(i, c) printf("%d ", tmp[i]); puts("");
    }
    //    rep(i, n) printf("%d ", a[i]); puts("");
    printf("%d\n", a[0]);
  }
  return 0;
}

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

int main() {
	int n, r;
	while(cin >> n >> r, n || r) {
		vector<int> v(n);
		iota(v.rbegin(), v.rend(), 1);
		
		for(int i = 0; i < r; ++i) {
			int p, c;
			cin >> p >> c;
			p--;
			auto temp = v;
			for(int j = 0; j < c; ++j) {
				temp[j] = v[p + j];
			}
			
			for(int j = 0; j < p; ++j) {
				temp[c + j] = v[j];
			}
			
			swap(v, temp);
		}
		cout << v[0] << endl;
	}
	return 0;
}