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>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int n,r,p,c;
	int card[64];
	while(cin>>n>>r,n|r){
		rep(i,n)card[i]=n-i;
		//p+c<=n+1
		rep(i,r){
			cin>>p>>c;
			int tmp[64];
			for(int k=0; k<c; k++){
				tmp[k] = card[p-1+k];
			}
			for(int k=0; k<p-1; k++){
				tmp[c+k] = card[k];
			}
			for(int k=p+c-1; k<n; k++){
				tmp[k] = card[k];
			}
			
			/*
			rep(k,n){
				printf("%d,",tmp[k]);
			}puts("");
			*/
			//copy
			rep(k,n){
				card[k]=tmp[k];
			}
		}
		printf("%d\n",card[0]);
	}
	
	return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int n,r;
	while(scanf("%d %d",&n,&r),n) {
		vector<int> v;
		for(int i=0;i<n;i++) {
			v.push_back(n-i);
		}
		for(int i=0;i<r;i++) {
			int p,c;
			scanf("%d %d",&p,&c);
			vector<int> a,b;
			for(int j=0;j+1<p;j++) {
				int e=v.front();v.erase(v.begin());
				a.push_back(e);
			}
			for(int j=0;j<c;j++) {
				int e=v.front();v.erase(v.begin());
				b.push_back(e);
			}
			for(int j=p-2;j>=0;j--) {
				v.insert(v.begin(),a[j]);
			}
			for(int j=c-1;j>=0;j--) {
				v.insert(v.begin(),b[j]);
			}
		}
		printf("%d\n",v[0]);
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;

int n, r;

struct opt {
	int p, c;
};

vector<opt> V;

int main() {
	while(cin >> n >> r, n | r) {
		V.clear();

		rep(i, r) {
			opt o;
			cin >> o.p >> o.c;
			V.push_back(o);
		}

		int a = 1;
		repd(i,V.size()-1,0) {
			if(a <= V[i].c) {
				a += V[i].p-1;
			} else {
				if(a - V[i].c <= V[i].p - 1) {
					a = a - V[i].c;
				}
			}
		}
		printf("%d\n", n-a+1);
	}
}

C++: #include <iostream>
#include <vector>
 
using namespace std;
 
void solve()
{
    int n, r;
    while(cin >> n >> r, n || r)
    {
        vector<int> Vec(n);
        for(int i = 0; i < n; ++i)
        {
            Vec[i] = n - i;
        }
        while(r--)
        {
            int p, c;
            cin >> p >> c;
            vector<int> VecBuf = Vec;
            int pos = 0;
            for(int i = p - 1; i < p + c - 1; ++i)
            {
                Vec[pos] = VecBuf[i];
                ++pos;
            }
            for(int i = 0; i < p - 1; ++i)
            {
                Vec[pos] = VecBuf[i];
                ++pos;
            }
            // for(int i = p + c - 1; i < n; ++i)
            // {
            //     Vec[pos] = VecBuf[i];
            //     ++pos;
            // }
        }
        cout << Vec[0] << endl;
    }
}
 
int main()
{
    solve();
    return(0);
}

C++: #include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int inf=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > p;

int n,r;
void solve() {
    vector<int> hana;
    for(int i=n;i>=1;i--) hana.pb(i);
    rep(i,r) {
        int p,c;
        cin>>p>>c;
        vector<int> tmp;
        for(int i=0;i<p-1;i++) tmp.pb(hana[i]);
        for(int i=0;i<c;i++) hana[i] = hana[i+p-1];
        for(int i=c;i<c+p-1;i++) hana[i]=tmp[i-c];
        //rep(i,hana.size()) cout<<hana[i]<<" ";
        //cout<<endl;
    }
    cout<<hana[0]<<endl;
}
int main() {
    while(cin>>n>>r) {
        if(n+r==0) break;
        solve();
    }

    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;
typedef unsigned long ulong;

void solve() {
	vector<int> res;
	while (true) {
		int n, r;
		cin >> n >> r;
		if (n == r && n == 0)break;

		vector<int> card;
		for (int i = 0; i < n; i++)card.push_back(n - i);

		for (int i = 0; i < r; i++) {
			int p, c;
			cin >> p >> c;
			vector<int> ps;
			vector<int> cs;
			for (int j = 0; j < p - 1; j++)ps.push_back(card[j]);
			for (int j = 0; j < c; j++) {
				card[j] = card[j + p - 1];
			}
			for (int j = 0; j < p - 1; j++)card[j + c] = ps[j];
		}
		res.push_back(card[0]);
	}
	for (int i = 0; i < res.size(); i++)cout << res[i] << endl;
}

int main()
{
	solve();
	return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = {-1,0,1,0}; const int dy[] = {0,1,0,-1};

int main() {
	int n, r;
	while(cin >> n >> r, n|r){
		vi list(n);
		REP(i, n) list[i] = i + 1;

		for(auto n:list)
			LOG("%d ", n);
		LOG("\n");

		REP(i, r){
			int p, c;
			cin >> p >> c;
			vi stk = {list.end()-(p+c-1),list.end()-(p-1)};
			list.erase(list.end()-(p+c-1),list.end()-(p-1));
			for(auto n:stk)
				list.push_back(n);

			for(auto n:list)
				LOG("%d ", n);
			LOG("\n");
		}

		cout << list[list.size() - 1] << endl;
	}
}