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 <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 <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int mincost[5001];
vector<pii> tx(5001);
vector<vector<int>> way(5001);
int main() {
	int n, r;
	while (cin >> n >> r, r) {
		vector<int> list(n);
		for (int i = 0; i < n; i++)list[i] = i + 1;
		for (int i = 0; i < r; i++) {
			int p, c;
			cin >> p >> c;
			vector<int> buf(list.end() - p + 1 - c, list.end() - p + 1);
			list.erase(list.end() - p + 1 - c, list.end() - p + 1);
			list.insert(list.end(), buf.begin(), buf.end());
		}
		cout << list.back() << endl;
	}
}

C++: #include<stdio.h>

int main(void){
  int n;
  int r;
  int p;
  int c;
  int i;
  int j;
  for(;;){
    scanf("%d %d",&n,&r);
    if(n==0)
      {
	if(r==0){break;}
      }
    int card[n];
    for(i=n;i>0;i--)
      {
	card[n-i]=i;
      }
    /*--------------確認用-------------------
    printf("card:");
    for(i=0;i<n;i++)
      {
	printf("%d ",card[i]);
      }
    printf("\n");
    /*--------------------------------------*/
    for(i=0;i<r;i++)
      {
	scanf("%d %d",&p,&c);
	int card_p[p-1];
	int card_c[c];
	for(j=0;j<p-1;j++)
	  {
	    card_p[j]=card[j];
	  }
	/*---------確認用-------------------------
	printf("card_p:");
	for(j=0;j<p-1;j++)
	  {
	    printf("%d ",card_p[j]);
	  }
	printf("\n");
	/*----------------------------------------*/
	for(j=0;j<c;j++)
	  {
	    card_c[j]=card[p+j-1];
	  }
	/*---------確認用-------------------------
	printf("card_c:");
	for(j=0;j<c;j++)
	  {
	    printf("%d ",card_c[j]);
	  }
	printf("\n");
	/*----------------------------------------*/
	for(j=0;j<c;j++)
	  {
	    card[j]=card_c[j];
	  }
	for(j=0;j<p-1;j++)
	  {
	    card[c+j]=card_p[j];
	  }
	/*-----------------------------------------
	for(j=0;j<n;j++)
	  {
	    printf("%d ",card[j]);
	  }
	printf("\n");
	/*----------------------------------------*/
      }
    printf("%d\n",card[0]);
  }
  
  return 0;
}

C++: //a.insert(a.end(),b.begin(),b.end()); ／aの末尾にbの全範囲を追加するわけね。ググってすぐに出てこなくて頭に来たのでここに書いておく
#include <iostream>
#include <vector>
using namespace std;
void makeHanafuda(vector<int> &vec){
  for(int i = 0;i < vec.size();i++){
    vec[i] = vec.size()-i;
  }
}
vector<int> shuffle(int p,int c,vector<int> &vec,int n){//pからcぬきとる
  //  cout << vec[2] << endl;
  vector<int> f(p-1,0);
  vector<int> s(c,0);
  vector<int> t(n - (p-1+c),0); 

  for(int i = 0;i < n;i++){
    if(i < p-1)f[i] = vec[i];
    else if(i < p-1+c)s[i-(p-1)] = vec[i];
    else t[i-(p-1+c)] = vec[i];
  
  }

  s.insert(s.end(),f.begin(),f.end());
  s.insert(s.end(),t.begin(),t.end());

  return s;
}
int main(){

  while(1){
    int n,r;
    cin >> n >> r;
    if(n == 0 && r == 0)break;
    vector<int> hanafuda(n,10);
    makeHanafuda(hanafuda);
    for(int i = 0;i < r;i++){
      int p,c;
      cin >> p >> c;
      hanafuda = vector<int>(shuffle(p,c,hanafuda,n));

    }
    cout << hanafuda[0] << endl;
    /*    cout << "0----------------" << endl;
    for(int i = 0;i < n;i++){
      cout << hanafuda[i] << endl;
      }*/

  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>

int main() {
	while (true) {
		int n, r;

		scanf("%d %d", &n, &r);

		if (n == 0) break;

		char s[50];
		char b[50];
		for (int i = 0; i < n; i++) s[i] = n - i;

		for (int i = 0; i < r; i++) {
			int p, c;
			scanf("%d %d", &p, &c);

			memmove(b, s + p - 1, c);
			memmove(s + c, s, p - 1);
			memmove(s, b, c);
		}

		printf("%d\n", s[0]);
	}

	return 0;
}

C++: //include
//------------------------------------------
#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 <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
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(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//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())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

//??????1??????N
int main(){
	VI Hanafuda;
	deque<int> HanafudaBuf;
	int N;
	int R;
	int p;
	int c;
	int r=INT_MIN;
	while (true){
		if (r != INT_MIN){ cout << endl; }
		cin >> N;
		cin >> R;
		if (N == 0 && R == 0){ break; }
		FOR(i, 1, N + 1){
			Hanafuda.push_back(i);
		}
		FOR(i, 0, R){
			cin >> p;
			cin >> c;
			for (int j = N - p; j >= N - p - c + 1; j--){
				HanafudaBuf.push_front(Hanafuda[j]);
			}
			if (p != 1 && c != N){ Hanafuda.erase(Hanafuda.begin() + N - c - p + 1, Hanafuda.begin() + N - c + 1); }
			for (int j = 0; j < c; j++){
				Hanafuda.push_back(HanafudaBuf[j]);
			}
		}
		r = Hanafuda[N - 1];
		cout << r;
		Hanafuda.clear();
		HanafudaBuf.clear();
	}
	return 0;
}