Go: package main

import "fmt"

func main() {
	var n, r int
	fmt.Scan(&n, &r)
	for n != 0 || r != 0 {
		arr := make([]int, n)
		for i := range arr {
			arr[i] = len(arr) - i
		}

		for i := 0; i < r; i++ {
			var p, c int
			fmt.Scan(&p, &c)
			mid, top, last := arr[:p-1], arr[p-1:p-1+c], arr[p-1+c:]
			arr = append(append(append([]int{}, top...), mid...), last...)
		}
		fmt.Println(arr[0])
		fmt.Scan(&n, &r)
	}
}

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;
}

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

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

void shuffle(int p, int c) {
	reverse(cards.begin(), cards.begin() + p);
	reverse(cards.begin() + p, cards.begin() + p + c);
	reverse(cards.begin(), cards.begin() + p + c);
}

int main() {
	while (1) {
		cin >> n >> r;
		if ( ! n && ! r) break;

		iota(cards.rend() - n, cards.rend(), 1);
		for (int i=0; i<r; ++i) {
			cin >> p >> c;
			shuffle(p - 1, c);
		}
		cout << cards[0] << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int card[51],s[51];
int n,r;
void shuffle(int p,int c){
	for(int i=1;i<p;i++){
		s[i]=card[i];
	}
	for(int i=1;i<=c;i++){
		card[i]=card[p-1+i];
	}
	for(int i=1;i<p;i++){
		card[i+c]=s[i];
	}
}


int main(){
	int p,c;
	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;
			shuffle(p,c);
			//for(int j=1;j<=n;j++){
			//	cout << card[j]<<" ";
			//}
		}
		cout <<card[1] <<endl;
	}
	return 0;
}