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

#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, a, b) for (int i = (a); i <= (b); i++)
#define repi(i, n) REPI(i, 0, n)
#define ALL(vs) (vs).begin(), (vs).end()
typedef long long ll;
typedef pair<int, int> pii;

#define MAX 52

void pop_front(vector<int> vs)
{
    reverse(ALL(vs));
    vs.pop_back();
    reverse(ALL(vs));
}

int main()
{
    int n, r;
    while (cin >> n >> r, n|r) {
        int arr[MAX];
        rep(i, n) arr[i] = i;
        reverse(arr, arr+n);

        rep(t, r) {
            int p, c;
            cin >> p >> c;

            int buf[MAX];
            rep(i, p-1) buf[i] = arr[i];
            rep(i, c)   arr[i] = arr[p-1+i];
            rep(i, p-1) arr[c+i] = buf[i];
        }

        printf("%d\n", arr[0]+1);
    }
    return 0;
}

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

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

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

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;

int main() {
	int n, r;

	while(cin >> n >> r, n) {
		vi yama(n);
		REP(i, n) {
			yama[i] = n-i;
		}

		int p, c;
		REP(i, r) {
			cin >> p >> c;
			
			vi yama1(p-1);
			REP(j, p-1) {
				yama1[j] = yama[j];
			}

			vi yama2(c);
			REP(j, c) {
				yama2[j] = yama[j+p-1];
			}

			vi yama3(0);
			REP(j, yama2.size()) {
				yama3.push_back(yama2[j]);
			}

			REP(j, yama1.size()) {
				yama3.push_back(yama1[j]);
			}

			REP(j, yama3.size()) {
				yama[j] = yama3[j];
			}
		}

		cout << yama[0] << endl;
	}



}

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

int main(){

  int n, r;
  int card[50];

  while(cin>>n>>r, n){
    for(int i=0;i<n;i++) card[i]=n-i;
    for(int i=0;i<r;i++){
      int p, c;
      cin>>p>>c;

      rotate(card, card+p-1, card+p+c-1);
    }

    cout<<card[0]<<endl;
  }

  return 0;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion


int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int n, r;

    while (true) {
        cin >> n >> r;
        if (!n && !r) break;

        vector<int> v(n);
        rep(i, 0, n) v[i] = n - i;

        rep(i, 0, r) {
//            for (int h : v) cout << h << " "; cout << endl;
            int p, r; cin >> p >> r;
            --p;
            vector<int> v2;
            rep(j, p, p + r) v2.push_back(v[j]);
            rep(j, 0, p) v2.push_back(v[j]);
            rep(j, p + r, n) v2.push_back(v[j]);
            v = v2;
        }
//        for (int h : v) cout << h << " "; cout << endl;

        cout << v[0] << endl;
    }
}

C++: #include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<vector>
using namespace std;
int array[51];
int main(){
  int M,N;
  vector<int> v;
  while(cin>>M >>N){
    if(N==0&&M==0){
      break;
    }
    for(int k=0;k<M;k++){//初期化
      array[k]=k+1;
    }
    int p=0,c=0;
    for(int i=0;i<N;i++){
      cin >>p >>c;

      for(int a=0;a<p-1;a++){//上保存
	v.push_back(array[(M-1)-a]);
      }

      for(int t=0;t<c;t++){//下を上へ
	array[(M-1)-t]=array[(M-1)-(p-1)-t];

      }

      for(int l=0;l<p-1;l++){//上を下へ
	array[(M-1)-c-l]=v.front();
	v.erase(v.begin());

      }

      /*
      for(int g=M-1;g>=0;g--){//配列確認
	cout << array[g] <<endl;
	}*/



    }
      cout << array[M-1] <<endl; 
  }
  
  return 0;
}