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 <iostream>
#include <algorithm>
#include <vector>
using namespace std;

#define repeat(i, n) for(int i = 0; i < (n); i++)

int main() {
    int n, r;
    while (cin >> n >> r) {
        if (n == 0 && r == 0) break;
        vector<int> pile(n);
        repeat(i, n) {
            pile[i] = n-i;
        }
        repeat(i, r) {
            int p, c; cin >> p >> c;
            vector<int> after(n);
            repeat(j, p-1) {
                after[j+c] = pile[j];
            }
            for (int j = p-1; j < p+c-1; j++) {
                after[j-p+1] = pile[j];
            }
            pile = after;
        }
        cout << pile[0] << endl;
    }
    return 0;
}

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

int main(){
  int n, r;
  cin >> n >> r;

  int p, c;
  while(n != 0 && r != 0){
    vector<int> v(n);
    vector<int> v1(n);
    for(int i = 0; i < n; i++){
      v[i] = n - i;
    }

    for(int i = 0; i < r; i++){
      cin >> p >> c;
      p--;

      for(int j = 0; j < n; j++){
        v1[j] = v[j];
      }

      for(int j = 0; j < c; j++){
        v[j] = v1[p + j];
      }

      for(int j = c; j < p + c; j++){
        v[j] = v1[j - c];
      }
        
      for(int j = 0; j < n; j++){
        //cerr << v[j] << " ";
      }
      //cerr << endl;
    }
    cout << v[0] << endl;
    cin >> n >> r;
  }

}

C++: #include <iostream>
#include <vector>

using namespace std;

int solve(int n,int r)
{
	if(r==0) return n;
	int p,c; cin>>p>>c;
	int x=solve(n,r-1);
	if(x>n-c)
		x-=(p-1);
	else if(n-c>=x && x>n-p-c+1)
		x+=c;
	return x;
}

int main()
{
	for(int n,r;cin>>n>>r,n|r;)
		cout<<solve(n,r)<<endl;
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int n, r, p, c;
	int cards[50], tmp[50];
	
	cin >> n >> r;

	while (n != 0 && r != 0) {
		for (int i = 0; i < n; i++) cards[i] = n - i;
		for (int i = 0; i < r; i++) {
			cin >> p >> c;
			for (int j = 0; j < p - 1; j++) tmp[j] = cards[j];
			for (int j = 0; j < c; j++) cards[j] = cards[p - 1 + j];
			for (int j = 0; j < p - 1; j++) cards[c + j] = tmp[j];
		}

		cout << cards[0] << endl;

		cin >> n >> r;
	}
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,R;
    cin >> N >> R;
    while(N){
        vector<int> V(N);
        iota(V.rbegin(), V.rend(), 1);
        for(auto i:V)cout << i << endl;
        rep(i,0,R){
            int p,c;
            cin >> p >> c;
            vector<int> tmp(p + c - 1);
            rep(j,0,c){
                tmp[j] = V[j + p - 1];
            }
            rep(j,c,p+c-1){
                tmp[j] = V[j-c];
            }
            rep(j,0,p+c-1){
                V[j] = tmp[j];
            }
        }
        cout << V[0] << endl;
        cin >> N >> R;
    }
}

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl;
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// Aliases
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int main() {
    while(true) {
        int n, r;
        cin >> n >> r;
        if(n == 0 && r == 0) break;
        int loc = 1;
        stack<pair<int, int>> st;
        REP(i, r) {
            int p, c;
            cin >> p >> c;
            st.push(pair<int, int>(p, c));
        }
        while(!st.empty()) {
            auto ro = st.top();
            st.pop();
            if(ro.second >= loc) {
                loc += ro.first - 1;
            }
            else if(ro.first + ro.second > loc) {
                loc -= ro.second;
            }
        }
        cout << n - loc + 1 << "\n";
    }

    return 0;
}

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

int main(){
    int n, r, p, c;
    int card[50];
    int ncard[50];
    cin >> n >> r;
    while(n || r){
        for(int i=0;i<n;++i){
            card[i] = i;
            ncard[i] = i;
        }
        for(int i=0;i<r;++i){
            cin >> p >> c;
            for(int j=0;j<c;++j){
                ncard[j] = card[p+j-1];
            }
            for(int j=c;j<c+p-1;++j){
                ncard[j] = card[j-c];
            }
            for(int j=c+p-1;j<n;++j){
                ncard[j] = card[j];
            }
            for(int j=0;j<n;++j){
                card[j] = ncard[j];
            }
        }
        cout << n-card[0] << endl;
        cin >> n >> r;
    }
}

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

typedef long long ll;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

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

ll A, B, C, D, E, F, G, H, I, J, K, L, M,
N, O, P, Q, R, S, T, U, V, W, X, Y, Z;

void aojHanafudaShuffle();
int main()
{
	aojHanafudaShuffle();
	return 0;
}

void aojHanafudaShuffle()
{
	N = R = 1;
	while (true) {
		cin >> N >> R;
		if (N == 0 and R == 0) break;

		vector<ll> cards(N);
		REP(i, N) cards[i] = i + 1;

		REP(i, R) {
			cin >> P >> C;
			vector<ll> tmp(C);
			copy(cards.begin() + (N - (C + P - 1)), cards.begin() + N - (P - 1), tmp.begin());
			copy(cards.begin() + (N - (P - 1)), cards.end(), cards.begin() + (N - (C + P - 1)));
			copy(tmp.begin(), tmp.end(), cards.begin() + (N - C));
		}

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

C++: // ・AOJ1142(setの練習問題)
// ・AOJ1129(vectorの練習問題)
// ・AOJ10032(stackの練習問題)
// ・AOJ10027(stringの練習問題)
// ・AOJ10021(sort || priority_queueの練習問題)
// ・AOJ1064(オーバーロードの練習問題)
// ・AOJ0138(mapの練習問題)
// ・AOJ0105(mapの練習問題)
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int main() {
	int n, r, p, c;
	vector<int> v;
	vector<int>::iterator ite;
	while(1){
		scanf("%d%d", &n, &r);
		if(n ==0 && r == 0) break;
		for (int i=1; i<=n; i++) { v.push_back(i); }
		for (int i=0; i<r; i++) {
			scanf("%d%d", &p, &c);
			ite = v.end()-p-c+1;
			for(int j=0; j<c; j++) {
				v.push_back(*ite);
				v.erase(ite);
			}
		// vector<int>::iterator test;
		// test = v.begin();
		// while(test != v.end()){printf("%d", *test); test++;}
		// printf("\n");
		}
		ite = v.end()-1;
		printf("%d\n", *ite);
	}
}