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 <stdio.h>
#include <string.h>

void shuffle(int card[50],int p,int c){
	int d[50],i;
	memcpy(d,card.50 * sizeof(int));
		for(i = 0;i < c;i++){
		d[i] = card[p - 1 + i];
	}
		for(i = 0; i < p - 1;i++){
			d[c + i] = card[i];
		}
	memcpy(card,d,50 * sizeof(int));
}


int main(void){
	int n,r,p,c,i,card[50];
	
	while(1){
		scanf("%d %d",&n,&r);
			if(n == 0 && r == 0) break;
		for(i = 0; i < n;i++){
			card[i] = i;
		}
		
		for(i = 0;i < n; i++){
			 scanf("%d %d",&p,&c);
			 shuffle(card,p,c);
			}
		printf("%d\n",(n + 1 - card[0]));
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	while (true) {
		int n, r;
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		int a[50];
		rep(i, n) a[i] = n - i;
		rep(j, r) {
			vector<int> v;
			int p, c;
			cin >> p >> c;
			REP(i, p - 1, p + c - 2) {
				v.push_back(a[i]);
			}
			rep(i, n) {
				if (p - 1 <= i && i <= p + c - 2) continue;
				v.push_back(a[i]);
			}
			//rep(i, n) {
			//	cout << v[i] << " ";
			//}
			//cout << endl;
			rep(i, n) a[i] = v[i];
		}
		cout << a[0] << endl;
	}

    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
int main(){
	int n,r;
	while(cin>>n>>r,n,r){
		int data[50],tmp[50];
		for(int i=0;i<n;i++){
			data[i]=n-i;
			tmp[i]=n-i;
		}
		for(int i=0;i<r;i++){
			int p,c;
			cin>>p>>c;
			for(int j=0;j<p+c-1;j++){
				if(j<p-1){
					tmp[j+c]=data[j];
				}else{
					tmp[j-p+1]=data[j];
				}
			}
			for(int j=0;j<n;j++){
				data[j]=tmp[j];
			}
		}
		cout<<data[0]<<endl;
	}
}

C++: #include <stdio.h>
int main(){
  int n,r,p,c,i,j,k,l,nh[51],s[51];
  while(1){
    scanf("%d%d",&n,&r);
    if(n==0&&r==0) break;
 
    for(i=n;i>=1;i--){
      nh[n-i+1]=i;
    }
  
    for(i=0;i<r;i++){
      scanf("%d%d",&p,&c);
      for(j=p;j<=p+c-1;j++){
        s[j]=nh[j];
      }
    l=0;
      for(j=1;j<=c;j++){
    for(k=p-1+l;k>=1+l;k--){
          nh[k+1]=nh[k];
    }
        l++;
      }
     
      for(j=p;j<=p+c-1;j++){
        nh[j-p+1]=s[j];
      }
    }
 
    printf("%d\n",nh[1]);
  }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int a[51],b[51];
int main(){
    int n,r,p,c;
    while(cin>>n>>r,n){
        rep(i,n) a[i]=n-i;
        rep(i,r){
            cin>>p>>c;
            FOR(j,p-1,p+c-1) b[j-p+1]=a[j];
            for(int j=p-2;j>=0;--j) a[j+c]=a[j];
            rep(j,c) a[j]=b[j];
        }
        cout<<a[0]<<endl;
    }
    return 0;
}

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

int main(){
    int n, r;
    while(cin >> n >> r, n != 0){
        vector<int> deck;
        for(int i=1;i<=n;++i)deck.push_back(i);
        for(int i=0;i<r;++i){
            int p, c;
            cin >> p >> c;
            for(int i=0;i<c;++i){
                deck.push_back(deck[n-(p-1+c)+i]);
            }
            deck.erase(deck.begin() + n-(p-1+c), deck.begin() + n-(p-1));
        }
        cout << deck.back() << endl;
    }

    return 0;
}

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

void shafle(int b, int e, int *ans)
{
    int tmp[50];
    b--;
    for (int i = 0; i < b; i++)
        tmp[i] = ans[i];
    for (int i = b; i < b + e; i++)
        ans[i - b] = ans[i];
    for (int i = e; i < b+e; i++)
        ans[i] = tmp[i - e];
}
int main()
{
    int n, r;
    while (cin >> n >> r, n)
    {
        int ans[50];
        for (int i = 0; i < n; i++)
            ans[i] = n - i;
        for (int i =0 ; i < r; i++) {
            int b, e;
            cin >> b >> e;
            shafle(b, e, ans);
        }
        cout << ans[0] << endl;
    }
    return 0;
}

C++: #include <stdio.h>
int main(){
    int n,r,card[100],p,c,temp[100];
    while(1){
        scanf("%d%d",&n,&r);
        if(n==0&&r==0)return 0;
        for(int i=1;i<=n;i++)card[i]=n-i+1;
        while(r--){
            scanf("%d%d",&p,&c);
            for(int i=1;i<=c;i++)temp[i]=card[i+p-1];
            for(int i=c+1;i<p+c;i++)temp[i]=card[i-c];
            for(int i=1;i<p+c;i++)card[i]=temp[i];
        }
        printf("%d\n",card[1]);
    }
}

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

using ll = long long;
#define int long long

// [a -> b-1]
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
// [0 -> a-1]
#define rep(i, a) reps(i, 0, (a))
// [a-1 -> b]
#define rreps(i, a, b) for (int i = (int)((a)-1); i >= (int)(b); i--)
// [a-1 -> 0]
#define rrep(i, a) rreps(i, a, 0)
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
 * (v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)\
	sort(all(v));\
	(v).erase(unique(all(v)), v.end())
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(15)
#define YES(f) cout << ((f) ? YES_STR : NO_STR) << endl;

using namespace std;

int solve(int n, int r) {
	vector<int> res(n);
	iota(res.rbegin(), res.rend(), 1);
	rep(i, r) {
		int p, c; cin >> p >> c;
		vector<int> t;
		t.insert(t.end(), res.begin() + p - 1, res.begin() + p + c - 1);
		t.insert(t.end(), res.begin(), res.begin() + p - 1);
		t.insert(t.end(), res.begin() + p + c - 1, res.end());
		res = t;
	}
	return res[0];
}

signed main() {
	int n, r;
	while (cin >> n >> r, n) cout << solve(n, r) << endl;
}