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 <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){
		vector<int> card(n);
		REP(i, n)
			card[i] = n-i;
		REP(i, r){
			int l, m;
			cin >> l >> m;
			l--;
			vector<int> card2(m);
			copy(card.begin() + l, card.begin() + l + m, card2.begin());
			card.erase(card.begin() + l, card.begin() + l + m);
			card2.insert(card2.end(), card.begin(), card.end());
			card = card2;
		}
		cout << card[0] << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, r;
    while(cin >> n >> r, n | r){
        vector<int> v(n);
        for (int i = 0; i < n; ++i) {
            v[i] = n-i;
        }
        for (int i = 0; i < r; ++i) {
            int p, c;
            cin >> p >> c;
            vector<int> u(c+p-1);
            for (int j = 0; j < c+p-1; ++j) {
                u[(j+c)%(c+p-1)] = v[j];
            }
            for (int j = 0; j < c+p-1; ++j) {
                v[j] = u[j];
            }
        }
        cout << v.front() << "\n";
    }
    return 0;
}

C++: #include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n,r,p,c;
	while(cin>>n>>r,n){
		vector<int> d(n),e(n); for(int i=0;i<n;i++)d[i]=n-i;
		for(int i=0;i<r;i++)cin>>p>>c,e=d,copy(d.begin(),d.begin()+p-1,e.begin()+c),
		copy(d.begin()+p-1,d.begin()+p-1+c,e.begin()),d=e;
		cout<<d[0]<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main() {
	int n, r;
	while (cin >> n >> r, n || r){
		stack<int> st;
		for (int i = 1; i <= n; i++)st.push(i);
		for (int i = 0; i < r; i++) {
			int p, c; cin >> p >> c;
			stack<int>st1, st2;
			for (int i = 0; i < p - 1; i++) { st1.push(st.top()); st.pop(); }
			for (int i = 0; i < c; i++) { st2.push(st.top()); st.pop(); }
			for (int i = 0; i < p - 1; i++) { st.push(st1.top()); st1.pop(); }
			for (int i = 0; i < c; i++) { st.push(st2.top()); st2.pop(); }
		}
		cout << st.top() << endl;
	}
}

C++: // {{{ include and macros
#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(a, b) for(int unsafe_cnt=a; unsafe_cnt < b;unsafe_cnt++)
#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;
// }}}

// {{{ put
void newline() {cout << endl;}
template <typename T> void display(T input){cout << input;}
template <typename T> void put(T input){display(input); newline();}
// }}}

vector<int> to_top(const vector<int> v
                  ,const int p   // ???????§????
                  ,const int c){
  vector<int> w;
  for(int i=p; i<p+c; i++){
    w.push_back(v[i]);
  }
  for(int i=0; i<v.size(); i++){
    if(!(p<=i && i<p+c)){
      w.push_back(v[i]);
    }
  }
  return w;
}

int main() {
  int n, r;
  while(cin >> n >> r && n){
    vector<int> v;
    for(int i=n; i > 0; i--){v.push_back(i);}
    // for(int i=0;i<v.size();i++){display(v[i]);display(" ");} put("");
    for(int i=0; i < r; i++){
      int p, c;
      cin >> p >> c;
      v = to_top(v, p-1, c);
      // for(int i=0;i<v.size();i++){display(v[i]);display(" ");}put("");
    }
    put(v[0]);
  }
}

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

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

void hanafudaShuffle(int p, int c, int n, int* cards) {
    int* cutCards = new int [c];
    for (int i = 0; i < c; i++) {
        cutCards[i] = cards[p - 1 + i];
    }
    for (int i = p - 2; i >= 0; i--) {
        cards[c + i] = cards[i];
    }
    for (int i = 0; i < c; i++) {
        cards[i] = cutCards[i];
    }
    delete[] cutCards;
}

int main() {
    while (true) {
        int n, r;
        cin >> n >> r;
        if ((n | r) == 0) {
            break;
        }
        int* cards = new int [n];
        for (int i = 0; i < n; i++) {
            cards[i] = n - i;
        }
        for (int i = 0; i < r; i++) {
            int p, c;
            cin >> p >> c;
            hanafudaShuffle(p, c, n, cards);
        }
        cout << cards[0] << endl;
        delete[] cards;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 128;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

int v[MAX];

void solve(void){
    while (1) {
        int n, r;
        scanf("%d %d\n", &n, &r);
        if (n == 0 && r == 0) break;
        rep(n, i) v[i] = n-i;
        rep(r, meaningless_) {
            int vv[n];
            rep(n, i) vv[i] = v[i];
            int p, c;
            scanf("%d %d\n", &p, &c);
            rep(c, j) {
                v[j] = vv[p-1+j];
            }
            rep(p-1, j) {
                v[c+j] = vv[j];
            }
        }
        printf("%d\n", v[0]);
    }
}

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