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>

using namespace std;

int main(){
  int n, r;
  int card[50];
  int cutp[50];
  int cutc[50];

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

    cout << card[n-1] << endl;
  }
  return 0;
}

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

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

	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

struct O{int p, c;};
int main()
{
	int n, r;
	while(cin >> n >> r && (n || r))
	{
		stack<O> order;
		rep(i, r)
		{
			O o;
			cin >> o.p >> o.c;
			order.push(o);
		}

		int res = 1;

		for(; !order.empty(); order.pop())
		{
			O o = order.top();

			if(res <= o.c)
				res += o.p - 1;
			else if(res <= o.c + o.p - 1)
				res -= o.c;
		}

		cout << n - res + 1 << endl;
	}
}

C++: // AOJ 1129
#include<iostream>
#include<vector>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

const int NMAX = 100;
int card[NMAX];

int main() {
  int n, r;
  while (cin >> n >> r and n) {
    for (int i = 1; i <= n; i++) {
      card[i] = n + 1 - i;
    }

    REP (R, r) { 
      int p, c;
      cin >> p >> c;
      vector<int> temp1, temp2;
      for (int i = 1; i <= p - 1; i++) {
        temp1.push_back(card[i]);
      }

      for (int i = p; i < p + c; i++) {
        temp2.push_back(card[i]);
      }

      temp2.insert(temp2.end(), temp1.begin(), temp1.end());
      
      for (int i = 0; i < temp2.size(); i++) {
        card[i + 1] = temp2[i];
      }

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

C++: #include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265


void f(int n,int r){
  int a[100];
  rep(i,n){
    a[i+1]=n-i;
  }

  rep(i,r){
    int p,c;
    cin>>p>>c;
    int b[100];
    rep(j,p){
      b[j]=a[j+1];
    }
    rep(j,c){
      a[j+1]=a[p+j];
    }
    rep(j,p){
      a[j+c+1]=b[j];
    }
    
  }

  cout<<a[1]<<endl;

}

int main(){
  while(1){
    int n,r;
    cin>>n>>r;
    if(n==0) break;
    f(n,r);
  }

  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <cstring>

using namespace std;
const int INF = (1<<30);
typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for (int i = 0; i < a; i++)

int sx, sy;

int gx, gy;

int qqq;

//各座標までの最短距離
int d[100][100];


//移動方向のベクトル
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

//汎用
ll ans = 0;
pair<int, int> red[101], blue[101];
ll BIG = 10000000000;

//累乗
ll POW(ll a, ll b) {
ll c = 1;
for (int i = 0; i < b; ++i) {
c *= a;
}
return c;
}

//階乗
int Kaijou(int a) {
if (a < 2) return 1;
return a * Kaijou(a - 1);
}


int A[200000];
int kinds[200001];


int main() 
{
	int n,r;
	while(1){
		cin >> n>> r;
		if (n == 0&&r==0) break;

		vector<int> s(n);
		iota(s.begin(), s.end(), 1);
		reverse(s.begin(), s.end());

		rep(i, r) {
			int p, c;
			cin >> p >> c;
			int toU[100] = { 0 }, toD[100] = { 0 };
			rep(i, c) {
				toU[i] = s[p - 1 + i];
			}
			rep(i, p - 1) {
				toD[i] = s[i];
			}
			rep(i, c) {
				s[i] = toU[i];
			}
			rep(i, p - 1) {
				s[i + c] = toD[i];
			}
		}
	
		cout << s[0] << endl;
	}
	cin >> qqq;
}

C++: 
#include<cstdio>
#include<iostream>
#include<string>
#include <algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<set>
using namespace std;
using ll = long long;

int n, r, a, b;
int t[100];
int u[100], size;
int main() {
	while (cin >> n >> r && n&&r) {
		for (int i = 0; i<n; i++)t[i] = n - i;
		for (int i = 0; i<r; i++) {
			cin >> a >> b;
			for (int j = 0; j<b; j++)u[j] = t[j + a - 1];
			for (int j = a - 2; j >= 0; j--)t[j + b] = t[j];
			for (int j = 0; j<b; j++)t[j] = u[j];
		}
		cout << t[0] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int n,r;
	while(cin>>n>>r and n>0){
		int a[n]; rep(i,n) a[i]=n-i;
		rep(i,r){
			int p,c; cin>>p>>c;
			rotate(a,a+p-1,a+p+c-1);
		}
		cout<<a[0]<<endl;
	}
	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, r, p, c;
    while (true) {
        cin >> n >> r;
        if (n == 0 && r == 0) {
            break;
        }
        vector<int> deck;
        for (int i = 0; i < n; i++) {
            deck.push_back(i + 1);
            // cout << deck[i] << endl;
        }
        for (int i = 0; i < r; i++) {
            cin >> p >> c;
            stack<int> s;
            for (int j = 0; j < c; j++) {
                // cout << "要素番号" << deck.size() - p - j << endl;
                s.push(deck[deck.size() - p - j]);
                // cout << "取り除いたもの" << s.top() << endl;
            }
            // cout << s.top() << endl;
            deck.erase(deck.begin() + (deck.size() - p - c + 1), deck.begin() + (deck.size() - p + 1));

            for (int j = 0; j < c; j++) {
                deck.push_back(s.top());
                s.pop();
            }
            // for (int afa = 0; afa < deck.size(); afa++) {
            //     cout << deck[afa] << endl;
            // }
        }
        cout << deck[deck.size() - 1] << endl;
    }
}