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 <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


bool solve(){
	while(1){
		int n,r;
		cin>> n>> r;
		if(n==0 && r==0) break;
		
		vector<vector<int> > a(2, vector<int>(n));
		for(int i=0;i<n;i++){
			a[0][i] = a[1][i]  = n-i;
		}
		
		for(int i=0;i<r;i++){
			int p, c;
			cin>> p>> c;
			for(int j=0;j<c;j++){
				a[1][j] = a[0][p+j-1];
			}
			for(int j=c;j<c+p-1;j++){
				a[1][j] = a[0][j-c];
			}
			for(int i=0;i<n;i++){
				a[0][i] = a[1][i];
			}
		}
		cout<< a[0][0]<< endl;
	}
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a ; i<b ; i++)
#define dump(x) cout << #x << " = " << x << endl

using namespace std;

int card[50];
int n, r;

int main(){

	while(cin >> n >> r){
		if(n==0) break;

		rep(i,0,n) card[i] = n - i;

		rep(i,0,r){
			int p, c;
			cin >> p >> c;
			int temp[p];

			rep(i,0,p) temp[i] = card[i];
			rep(i,0,c) card[i] = card[p-1 + i];
			rep(i,0,p) card[c + i] = temp[i];

		}

		cout << card[0] << endl;

	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int ca[51],tmp[51];
int main(){
  int n,r;
  while(cin>>n>>r,n+r){
    for(int i=0;i<n;++i) ca[i]=n-i;
    int p,c;
    for(int i=0;i<r;++i){
      cin>>p>>c;
      for(int j=0;j<c;++j) tmp[j]=ca[p+j-1];
      for(int j=p-2;j>=0;--j) ca[j+c]=ca[j];
      for(int j=0;j<c;++j) ca[j]=tmp[j];
    }
    cout<<ca[0]<<endl;
  }
  return 0;
}

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

vector<int> v;

void shuffle(int p,int c) {
  vector<int> t;
  for(int i=0; i<c; i++)
    t.push_back(v[p-1+i]);
  for(int i=0; i<p-1; i++)
    t.push_back(v[i]);
  for(int i=p-1+c; i<v.size(); i++)
    t.push_back(v[i]);
  v = t;
}

int main() {
  while(1) {
    int n,r;
    cin>>n>>r;
    v.clear();
    if(!n&&!r) break;

    for(int i=0; i<n; i++)
      v.push_back(n-i);

    int p,c;
    while(r--) {
      cin>>p>>c;
      shuffle(p,c);
    }
    cout<<v[0]<<endl;
  }
}

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

using namespace std;

int main(){
	int n, r;
	while (cin >> n >> r, n&&r) {
		vector<int> pc(n);
		for (int i = 0; i < n; i++) pc[i] = n-i;
		for (int i = 0; i < r; i++) {
			int p, c; cin >> p >> c;
			vector<int> tmp(c);
			for (int j = 0; j < c; j++) {
				tmp[j] = pc[p-1+j];
			}
			for (int j = p-2; j >= 0; j--) {
				pc[j+c] = pc[j];
			}
			for (int j = 0; j < tmp.size(); j++) {
				pc[j] = tmp[j];
			}
		}
		cout << pc[0] << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	while(1){
		ll n,r;
		cin >> n >> r;
		if(n==0&&r==0)break;
		vector<ll> card(n);
		FOR(i,0,n)card[i]=i+1;
		FOR(i,0,r){
			ll p,c;
			cin >> p >> c;
			rotate(card.end()-p-c+1,card.end()-p+1,card.end());
		}
		cout << card[n-1] << endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<complex>
#include<numeric>
#include<bitset>
#define INF 1001001001
#define EPS 0.000000001

using namespace std;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int,int> pint;

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

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

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

#define ll long long

using namespace std;

int main(void) {
	while (1) {
		ll n, r;
		cin >> n >> r;
		if (n == 0 && r == 0)break;
		vector<ll> a(n);
		for (int i = n; i > 0; i--) {
			a[n - i] = i;
		}
		for (int i = 0; i < r; i++) {
			ll pos, num;
			cin >> pos >> num;
			vector<ll> s(num);
			for (int j = 0; j < num; j++) {
				s[j] = a[pos - 1 + j];
			}
			a.erase(a.begin() + pos - 1, a.begin() + pos - 1 + num);
			/*for (auto i = a.begin(); i != a.end();i++) {
				cout << *i;
			}
			cout << endl << "!!!" << endl;*/
			for (int i = 0; i < a.size(); i++) {
				s.push_back(a[i]);
			}
			a.resize(n);
			copy(s.begin(), s.end(), a.begin());
			/*for (auto i = a.begin(); i != a.end(); i++) {
				cout << *i;
			}
			cout << endl << "???" << endl;*/
		}
		cout << a[0] << endl;
	}
	return 0;
}

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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

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

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

int main(void)
{
	while (1) {
		int n, r;
		cin >> n >> r;
		if (n == 0) {
			break;
		}
		vector<int> dekki(n);
		for (int i = n; i >= 1; --i) {
			dekki[n - i] = i;
		}
		for (int i = 0; i < r; ++i) {
			int p, c;
			cin >> p >> c;
			vector<int> vec(p + c);
			for (int j = p - 1; j < p + c - 1; ++j) {
				vec[j - p + 1] = dekki[j];
			} 
			for (int j = 0; j < p - 1; ++j) {
				vec[c + j] = dekki[j];
			}

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

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

	return 0;
}