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 <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 - i);
        }
        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<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  while(1){
    int n,r;
    cin>>n>>r;
    if(n==0) break;
    int p,c;
    int a[n];
    for(int i=n-1;i>=0;i--){
      a[i]=n-i;
    }
    for(int i=0;i<r;i++){
      cin>>p>>c;
      rotate(a,a+p-1,a+p+c-1);
    }
    cout<<a[0]<<endl;
  }
    

  return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
	int n,r,p,c;
	int huda[51],hoge[51];

	while(1){

		//n:RDÌ  r:DðØéñ
		cin >> n >> r;
		if(n==0 && r==0)break;//0 0¾Á½çI¹

		//RDª5Èçã©çÉ54321ÆÈéæ¤É·é
		for(int i=0 ; i<n ; i++){
			huda[i] = n-i;
			hoge[i] = huda[i];
		}
		
		//rñ¾¯RDðVbt·é
		for(int i=0 ; i<r ; i++){
			//ã©çpÚÌD©çc²«æèRDÌêÔãÉÁÄ­é
			cin >> p >> c;
			p--;

			//ã©çpÚ©çp+cÚÜÅðêÔãÉÁÄ­éìðs¤
			for(int j=0 ; j<c ; j++){
				hoge[j] = hoge[p+j];
			}
			//cèÌDðºÉÁ¦é
			for(int j=0 ; j<p ; j++){
				hoge[c+j] = huda[j];
			}
			
			//ÅãÉhogeðhudaÉRs[·é
			for(int j=0 ; j<51 ; j++){
				huda[j] = hoge[j];
			}
		}

		//¦ÌoÍ
		cout << huda[0] << endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int a[51]={};
  int st[51]={};
  int n,r;
  int p,c;
  while(1){
    //in
    cin >> n >> r;
    if(n==0&&r==0)break;
    for(int i=0;i<n;i++){
      a[i]=n-i;
    }
    for(int i=0;i<r;i++){
      cin >> p >>c; 
      for(int j=0;j<n;j++){
	st[j]=a[j];
      }
      for(int j=0;j<c+1;j++){
	a[j]=st[p+j-1];
      }
      for(int j=0;j<p;j++){
	a[j+c]=st[j];
      }
    }
    cout << a[0] << endl;
  }
  return 0;
}

C++: #include <cstdio>

using namespace std;

int main()
{
	int n, r;
	int c[50], d[50];
	
	while (scanf("%d %d", &n, &r) && n){
		for (int i = 0; i < n; i++) c[i] = n - i;
		
		for (int i = 0; i < r; i++){
			int p, dx;
			scanf("%d %d", &p, &dx);
			for (int j = 0; j < n; j++) d[j] = c[j];
			for (int j = 0; j < p - 1; j++) d[j + dx] = c[j];
			for (int j = 0; j < dx; j++) d[j] = c[j + p - 1];
			for (int j = 0; j < n; j++) c[j] = d[j];
		}
		
		printf("%d\n", c[0]);
	}
}

C++: #import<cstdio>
#import<vector>
#import<algorithm>
main(){for(int i,r,n,p,c;scanf("%d%d",&n,&r),n;){std::vector<int> v;for(i=n;i;i--)v.push_back(i);for(i=0;i<r;i++)scanf("%d%d",&p,&c),p--,std::rotate(v.begin(),v.begin()+p,v.begin()+p+c);printf("%d\n",v[0]);}}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
  int n,r;
  while(cin >> n >> r, n){
    int npos[100];
    for(int i=n-1,j=0;i>=0;i--,j++){
      npos[j] = i+1;
    }
    for(int i=0;i<r;i++){
      int a,b;
      cin >> a >> b;
      int tmp[b];
      for(int j=0;j<b;j++){
	tmp[j] = npos[j+a-1];
      }
      for(int j=a+b-2;j>=b;j--){
	npos[j] = npos[j-b];
      }
      for(int j=0;j<b;j++){
	npos[j] = tmp[j];
      }
    }
    cout << npos[0] << endl;
  }
}

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

int main(){
  int n,r;
  int p,c;
  while(true){
    cin >> n >> r;
    if(n == 0 && r == 0) break;
    int cards[n];
    int result[n];
    for(int index=0;index<n;index++){
      cards[index] = n - index;
    }
    for(int i=0;i<r;i++){
      cin >> p >> c;
      for(int j=0;j<n;j++){
        if(j < c){
          result[j] = cards[p-1+j];
        }else if(j < c + p - 1){
          result[j] = cards[j-c];
        }else{
          result[j] = cards[j];
        }
      }
      for(int k=0;k<n;k++) cards[k] = result[k];
    }
    cout << cards[0];
    cout << endl;
  }
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define fi first
#define se second
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

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

    int n, r;
    cin >> n >> r;
    while(!(n==0 && r==0)){
        vector<int> a(n);
        REP(i, n) a[i] = n-i;
        REP(i, r){
            int p, c;
            cin >> p >> c;
            p--;
            vector<int> a_cp(a);
            REP(i, n){
                if(i < c) a_cp[i] = a[p+i];
                else if(i < c+p) a_cp[i] = a[i-c];
                else a_cp[i] = a[i];
            }
            copy(All(a_cp), a.begin());
        }
        cout << a[0] << "\n";
        cin >> n >> r;
    }
    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <cstring>

using namespace std;
const int INF = (1<<30);
typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for (int i = 0; i < a; i++)

int sx, sy;

int gx, gy;

int qqq;

//各座標までの最短距離
int d[100][100];


//移動方向のベクトル
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

//汎用
ll ans = 0;
pair<int, int> red[101], blue[101];
ll BIG = 10000000000;

//累乗
ll POW(ll a, ll b) {
ll c = 1;
for (int i = 0; i < b; ++i) {
c *= a;
}
return c;
}

//階乗
int Kaijou(int a) {
if (a < 2) return 1;
return a * Kaijou(a - 1);
}


int A[200000];
int kinds[200001];


int main() 
{
	int n,r;
	while(1){
		cin >> n>> r;
		if (n == 0&&r==0) break;

		vector<int> s(n);
		iota(s.begin(), s.end(), 1);
		reverse(s.begin(), s.end());

		rep(i, r) {
			int p, c;
			cin >> p >> c;
			int toU[100] = { 0 }, toD[100] = { 0 };
			rep(i, c) {
				toU[i] = s[p - 1 + i];
			}
			rep(i, p - 1) {
				toD[i] = s[i];
			}
			rep(i, c) {
				s[i] = toU[i];
			}
			rep(i, p - 1) {
				s[i + c] = toD[i];
			}
		}
	
		cout << s[0] << endl;
	}
	cin >> qqq;
}