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++: #define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int n, r; cin >> n >> r;
		if (n == 0) break;
		string s(n, ' ');
		for (int i = 0; i < n; i++) s[i] = n - i;
		while (r--) {
			int p, c; cin >> p >> c;
			string _s = s.substr(p - 1, c) + s.substr(0, p - 1) + s.substr(p + c - 1);
			s = _s;
		}
		cout << (int)s[0] << endl;
	}
}

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

using namespace std;

int main(){
    tuple<int,int,int> a;
}

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

int main() {
int N,R,p,c;
while (cin>>N>>R&&N) { 
	int A[100]={};
	for(int i=0;i<N;i++){
		A[i]=i+1;
	}
	reverse(A,A+N)
	for (int i=0; i<R; ++i) {
	cin >> p >> c ;
	rotate(A,A+p,A+p+c);

 }
 cout << A[0] << endl;
 }
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#define pi 3.14159
using namespace std;


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


	return 0;
}

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

int main(){
    int n,r;
    for(;;){
        scanf("%d%d",&n,&r);
        if(n==0 && r==0) break;
        int p,c;
        vector<int> ca(n);
        for(int i=0;i<n;i++){
            ca[i]=n-i;
        }
        for(int i=0;i<r;i++){
            scanf("%d%d",&p,&c);
            rotate(begin(ca),begin(ca)+p-1,begin(ca)+p-1+c);
        }
        printf("%d\n",ca[0]);
    }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int d[55];

void init(int n){
  for(int i=0;i<51;i++){
    d[i]=n-i;
  }
}

int main(){
  int n,r;

  while(true){
    cin>>n>>r;
    if(n==0&&r==0)break;
    init(n);
    for(int i=0;i<r;i++){    
      int p,c;
      cin>>p>>c;
  
      int tmp[55];
      for(int j=0;j<c;j++){
        tmp[j]=d[p+j-1];
      }
      //if(debug)for(int j=0;j<c;j++)cout<<tmp[j]<<" ";
      for(int j=p-1;j>0;j--){
	d[j+c]=d[j];
      }
      for(int j=0;j<c;j++){
	d[j]=tmp[j];
      }
      if(debug)for(int j=0;j<n;j++)cout<<d[j]<<" ";
      if(debug)cout<<endl;
    }
    cout<<d[0]<<endl;
  }
  return 0;
}

/*

1 2 3 4 5 
3 1 2 4 5


 */

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n,r;
	while(cin>>n>>r,r){
		int cards[60],i;
		for(i=0;i<60;i++)cards[i]=i;
		for(i=0;i<r;i++){
			int a,b;
			cin>>a>>b;
			a--;
			int j;
			int c[60];
			for(j=0;j<60;j++){
				if(j<b){
					c[j]=cards[a+j];
				}else if(j<a+b){
					c[j]=cards[j-b];
				}else{
					c[j]=cards[j];
				}
			}
			for(j=0;j<60;j++){
				cards[j]=c[j];
//cout<<cards[j]<<endl;
			}
//cout<<endl;
		}
		cout<<n-cards[0]<<endl;
	}
	return 0;
}

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

int erase_alt(list<int> &lis, list<int>::iterator itr)
{
	int temp = *itr;
	lis.erase(itr);
	return temp;
}

int main()
{
	while (true)
	{
		list<int> list0;
		int n, r;
		cin >> n >> r;
		if (n == 0 && r == 0)break;
		for (int i=n; i > 0; i--)
		{
			list0.push_back(i);
		}
		for (int i = 0; i<r; i++)
		{
			int p, c;
			list<int>::iterator itr = list0.begin();
			cin >> p >> c;
			if (p == 1)continue;
			advance(itr, p - 1);
			list0.splice(list0.begin(), list0, itr, next(itr, c));

		}
		cout << *list0.begin() << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
	int n, r;
	vector<int> card;
	vector<int> card2;
	while(true){
		cin >> n >> r;
		if(!n && !r) break;
		card.clear();
		// 1 .. n
		for(int i = 1; i <=n ; i++){
			card.push_back(i);
		}

		for(int i = 0; i < r; i++){
			int p, c;

			cin >> p >> c;
			if(n == c) continue;
			
			vector<int>::iterator it = card.end() - p - c + 1;
			
			// temp
			for(int j = 0; j < c; j++){
				card.push_back(*it);
				it++;
			}
			
			
			//erase
			card.erase(it  - c, it);
			
			it = card.begin();
			while(it != card.end()){
				cout << " " << *it ;
				it ++;
			}
			cout << endl;
			
		}
		cout << card[n-1] << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

ll v[100];

int main()
{
	cin >> n >> k;
	if (n == 0 && k == 0) {
		return 0;
	} else {
		vi v(n + 1);
		REP(i, n + 1)
			v[i] = n + 1 - i;
		REP(i, k)
		{
			ll p, c;
			cin >> p >> c;
			REP(j, c)
			{
				ll tmp = v[p + j];
				for (int l = p; l >= 1; l--) {
					v[j + l] = v[j + l - 1];
				}
				v[j + 1] = tmp;
			}
		}
		cout << v[1] << endl;
	}
}