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 <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for (int i=(n)-1;i>=0;i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define REPS(i,f,n) for (int i=(f)-1;i>=(n);i--)
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};

void slove(int n, int r){//n ???????????° r ??????????????°
	stack<int> s;
	rep(i, n) s.push(i);//?????????

	rep(i, r){//r????????????
		int p, c;
		cin >> p >> c;
		stack<int> tmp1;
		stack<int> tmp2;
		rep(i, p - 1){
			tmp1.push(s.top());
			s.pop();
		}
		rep(i, c){
			tmp2.push(s.top());
			s.pop();
		}

		rep(i, c){
			s.push(tmp2.top());
			tmp2.pop();
		}
		rep(i, p - 1){
			s.push(tmp1.top());
			tmp1.pop();
		}
	}

	printf("%d\n", s.top());
	return;
}

int main(void){
	int n, r;
	cin >> n >> r;
	while(n != 0 || r != 0){
		slove(n, r);
		cin >> n >> r;
	}
	return 0;
}

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);
	}
}

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

int main() {

  int n, r;
  int card[64];
  int card2[64];
  int p, c;

  for(;;) {
    std::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) {
      std::cin >> p >> c;

      for(int j = 0; j < p-1; ++j) {
	card2[j+c] = card[j];
      }

      for(int j = p-1; j < c+p-1; ++j) {
	card2[j-p+1] = card[j];
      }

      for(int j = 0; j < c+p-1; ++j) {
	card[j] = card2[j];
      }
    }
    std::cout << card[0] << std::endl;
  }
  
  return 0;
}

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-p-c<x && x<=n-c)
		x+=c;
	return x;
}

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

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
const double PI=acos(-1.0);
//---------------------------------------------------------------------------//
int n,r;
int a[51],b[51],c[51];
int main(){
        while(1) {
                cin>>n>>r;
                if(n==0 && r==0) {
                        return 0;
                }
                for(int i=0; i<r; i++) {
                        cin>>a[i]>>b[i];
                }

                for(int i=0; i<n; i++) {
                        c[i]=i;
                }
                for(int i=0; i<r; i++) {
                        for(int j=0; j<a[i]-1; j++) {
                                c[j]+=b[i];
                        }
                        for(int j=a[i]-1; j<a[i]-1+b[i]; j++) {
                                c[j]-=(a[i]-1);
                        }
                }
                for(int i=0; i<n; i++) {
                        if(c[i]==0) {
                                cout<<n-i<<endl;
                                return 0;
                        }
                }
        }
}

C++: #include<iostream>
using namespace std;
int main(){
	int huda[101];
	int n,r;
	while(cin>>n>>r,n||r){
	int p,c;
	for(int i=0;i<101;i++)huda[i]=i+1;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			for(int j=n-p-c+1;j<n-p+1;j++){
				//for(int x=0;x<n;x++)cout<<huda[x]<<" ";cout<<endl;
				int tmp=huda[n-p-c+1];
				for(int k=n-p-c+1;k<n-1;k++){
					huda[k]=huda[k+1];
				}
				huda[n-1]=tmp;
			}
		}
		cout<<huda[n-1]<<endl;
		for(int fjl=0;fjl<101;fjl++)huda[fjl]=0;
	}
	return 0;
}

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

int main(){
	int n,r,p,c;
	while(true){
		vector<int> a,b;
		cin >> n >> r;
		if(n==0 && r == 0)	break;
		a.resize(n);b.resize(n);
		for(int i = 0; i < n; ++i){
			a[i] = i;
		}
		for(int  i = 0; i < r; ++i){
			cin >> p >> c;

			for(int j = n-p-c+1; j < n; ++j){
				b[j] = a[j];
			}
			for(int j = n-p-c+1; j < n-p+1; ++j){
				a[j+p-1] = b[j];
			}
			for(int j = n-p+1; j < n; ++j){
				a[j-c] = b[j];
			}
		}
		cout << a[n-1]+1 << endl;
	}
}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;


int main(void) {
	
	while (1) {
		int n, r;
		int p, c;
		int a[51] = {};
		int b[51] = {};
		FOR(i, 1, n) {
			a[i] = n - i + 1;
		}
		cin >> n >> r;
		if (n == 0 && r == 0) {
			break;
		}
		FOR(i, 1, r) {
			cin >> p >> c;
			FOR(t, 1, p - 1) {
				b[t] = a[t];
			}
			FOR(t, 1, c) {
				a[t] = a[p + t - 1];
			}
			FOR(t, 1, p - 1) {
				a[p + t - 1] = b[t];
			}
		}
		cout << a[1] << endl;
	}

}

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

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

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

			rep(i, p) a[i] = card[i];
			rep(i, c) b[i] = card[p+i-1];
			rep(i, c) card[i] = b[i];
			rep(i, p) card[i+c] = a[i];

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