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<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
ll dx[4] = {1,0,0,-1};
ll dy[4] = {0,1,-1,0};

#define ARRAY_MAX 1005

int main(){

    int n,r,p,c;

    while(cin >> n >> r,n){
        vector<int> a(n);
        REP(i,n){
            a[i] = n-i;
        }
        REP(j,r){
            //r回の試行
            vector<int> b;//上にもっていく要素
            cin >> p >> c;
            //cout << p << " " << c << endl;
            for(int k = p-1+c-1;k >= p-1;k--){
                b.push_back(a[k]);
                a.erase(find(a.begin(),a.end(),a[k]));
            }
            REP(k,b.size()){
                a.insert(a.begin(),b[k]);
            }
            b.shrink_to_fit();
        }
        /*REP(m,a.size()){
            cout << a[m] << " ";
        }
        cout << endl;*/
        cout << a[0] << endl;
        a.shrink_to_fit();
        //cout << "a" << endl;
    }

    return 0;
}

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

int main(void){
  vector<int> f;
  while(1){
    f.clear();
    int n, r, p, c;
    cin >> n >> r;
    if(n == 0 && r == 0) return 0;
    for(int i=n; i > 0; i--){
      f.push_back(i);
    }


    vector<int> t;
    for(int i=0; i < r; i++){
      cin >> p >> c;
      t.clear();
      for(int j=p-1; j < p+c-1; j++){
        t.push_back(f.at(j));
      }
      for(int j=p-1; j > 0; j--){
        f.at(j+c-1) = f.at(j-1);
      }
      for(int j=0; j < c; j++){
        f.at(j) = t.at(j);
      }
      for(int j=0; j < f.size(); j++)
        cout << f[j] << " ";
      cout << endl;


    }
    cout << f.front() << endl;
  }
}

C++: #include <iostream>
#include <list>
#include <cstdlib>

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	int n,r;

	cin >> n;
	cin >> r;

	while (n != 0 || r != 0) {
		std::list<int> lst;
		int now = 1;

		for (int i = 0; i < n; i++) {
			lst.push_back(i+1);
		}

		for (int i = 0; i < r; i++) {
			int index = 1;
			int p,c;
			cin >> p;
			cin >> c;

			for (std::list<int>::iterator itr = lst.begin(); itr != lst.end();) {
				if (index >  n-(p-1)-c && index < n-(p-2)){
					lst.push_back(*itr);
					itr = lst.erase(itr);
				}else{
					itr++;
				}	
				index++;
			}
		}
		for (std::list<int>::iterator itr = lst.begin(); itr != lst.end(); ++itr) {
			if (now == n) {
				cout << *itr << endl;
			}
			now++;
		}
		cin >> n;
		cin >> r;
	}	
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double EPS = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int n, r;
int p, c;

int main() {
	while (cin >> n >> r, n && r) {
		if (n == 1) {
			cout << 1 << endl;
			continue;
		}

		vector<int> card;
		for (int i = n; i > 0; --i) card.push_back(i);
		rep(i, r) {
			cin >> p >> c;
			vector<int> tmp;
			rep(j, c) tmp.push_back(card[p - 1 + j]);
			rep(j, p - 1) tmp.push_back(card[j]);
			REP(j, p + c - 1, n) tmp.push_back(card[j]);
			card = tmp;
		}
		cout << card[0] << endl;
	}
}

C++: #include <stdio.h>

void c_copy(int c_tmp[], int data[], int p, int c, int n) {
  int i = 0;
  for (i = 0; i < c; i++) {
    c_tmp[i] = data[n-p+i-c+1];
    //    printf("i =%d n=%d n-p+i-c = %d\n",i,n,n-p+i-c+1);
  }
}

void move(int data[], int p, int c, int n) {
  int i;
  for (i = n-p+1; i < n; i++) {
    data[i-c] = data[i];
  }
}

void tmp_in(int c_tmp[], int data[], int p, int c, int n) {
  int i;  
  for (i = n-c; i < n; i++) {
    data[i] = c_tmp[i-n+c];
  }
}

void print(int data[], int n) {
  for (int i = 0; i < n; i++) {
    printf("%d ",data[i]);
  }
  puts("");
}

int main(void) {
  int data[200] ;
  int n[100];
  int r[100];
  int p[100][100];
  int c[100][100];
  int c_tmp[100][100];
  int i = 0, j = 0;
  int N;

  while (1) {
    scanf("%d", &n[i]);
    scanf("%d", &r[i]);
    if (n[i] == r[i] && n[i] == 0) {
      break;
    }
    for (j = 0; j < r[i]; j++) {
      scanf("%d", &p[i][j]);
      scanf("%d", &c[i][j]);
    }
    i++;
  }
  N = i;

  
  for (i = 0; i < N; i++) {
    for (j = 0; j < 200; j++) {
      data[j] = j+1;
    }
    for (j = 0; j < r[i]; j++) {
      // print(data, n[i]);//
      
      c_copy(c_tmp[i], data, p[i][j], c[i][j], n[i]);//
      // printf("c_copy = ");
      // print(c_tmp[i], n[i]);//
      
      move(data, p[i][j], c[i][j], n[i]);
      // printf("move\n");
      // print(data, n[i]);
      
      tmp_in(c_tmp[i], data, p[i][j], c[i][j], n[i]);
      // print(data, n[i]);
      // puts("");
    }
    printf("%d\n",data[n[i]-1]);
  }
  
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
  int ocs[100], ods[100];
  for(;;) {
    int n, r;
    cin >> n >> r;
    if(n == 0) break;
    int *cs = ocs;
    int *ds = ods;
    for(int i = 0; i < n; i++) {
      cs[i] = n - i;
    }
    for(int i = 0; i < r; i++) {
      int p, c;
      cin >> p >> c;
      for(int j = 0; j < c; j++) {
        ds[j] = cs[p - 1 + j];
      }
      for(int j = 0; j < p - 1; j++) {
        ds[j + c] = cs[j];
      }
      for(int j = c + p; j < n; j++) {
        ds[j] = cs[j];
      }
      int *tmp = cs;
      cs = ds;
      ds = tmp;
    }
    cout << cs[0] << endl;
  }
  return 0;
}

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

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

int main(){
	int cards[50];
	int t[50];
	int s[50];
	int n, r;
	int p, c;
	while(cin >> n >> r, n || r){
		for(int i=0; i < n; i++){
			cards[i] = n-i;
		}
		for(int i=0; i < r; i++){
			cin >> p >> c;
			for(int j=0; j < p-1; j++)
				t[j] = cards[j];
			for(int j=p-1; j < p+c-1; j++)
				s[j-p+1] = cards[j];
			for(int j=0; j < c; j++)
				cards[j] = s[j];
			for(int j=c; j < c+p-1; j++)
				cards[j] = t[j-c];
		}
		cout << cards[0] << endl;
	}
}