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 <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;


void show_tower(vector<int> &d) {
    cout << endl;
    for (int _d : d) {
      cout << _d << endl;
    }
    cout << endl;
}


int main() {
  int n, r;
  int s, f, w, k;

  while (cin >> n >> r && n && r) {

    // begin initialize vector
    vector<int> d(n);
    for (int i=0; i<n; i++) {
      d[i] = n-i;
    }
    // end initialize vector

    // begin r times operation
    for (int i=0; i<r; i++) {
      cin >> s >> f;
      s--;

      // begin initialize tmp vector
      vector<int> tmp(n);
      for (int j=0; j<n; j++) {
        tmp[j] = 0;
      }
      // end initialize tmp vector

      // begin copy selected elements
      for (int k=0; k<f; k++) {
        tmp[k] = d[s];
        d[s] = -1;
        s++;
      }
      // end copy selected elements

      // begin find non-zero index
      int k = 0;
      for (;k<n; k++) {
        if (tmp[k] == 0) break;
      }
      // end find non-zero index

      for (int _d : d) {
        if (_d > 0) tmp[k++] = _d;
      }

      d = tmp;
    }
    cout << d[0] << endl;
  }
}

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

using namespace std;

int32_t main()
{
  while(true){
    uint32_t n, r;
    cin >> n >> r;
    if(n == 0) break;

    vector<uint32_t> cards(51, 0);
    for(int32_t i = n-1, j = 1;  i >= 0; i--, j++){
      cards[i] = j;
    }

    for(uint32_t i = 0; i < r; i ++){
      uint32_t p, c;
      cin >> p >> c;
      vector<uint32_t> cs;
      for(uint32_t i = p - 1; i < p - 1 + c; i++){
        cs.push_back(cards[i]);
      }
      for(uint32_t i = 0; i < p - 1; i++){
        cs.push_back(cards[i]);
      }
      for(uint32_t i = p - 1 + c - 1; i < n; i++){
        cs.push_back(cards[i]);
      }

      for(uint32_t i= 0; i < n; i++){
        cards[i] = cs[i];
      }
    }

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

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);

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

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

int main(){
	while(true){
		int n, r, p, c;
		cin >> n >> r;
		if ((not n) && (not r)) break;
		int card1[n], card2[n];
		for (int i = 0; i < n; ++i){
			card1[i] = n - i;
			card2[i] = n - i;
		}
		for (int i = 0; i < r; ++i){
			cin >> p >> c;
			for (int j = 0; j < n; ++j){
				if (i % 2){
					if (j < c){
						card1[j] = card2[p-1+j];
					}else if(j < c + p - 1){
						card1[j] = card2[j-c];
					}else{
						card1[j] = card2[j];
					}
				}else{
					if (j < c){
						card2[j] = card1[p-1+j];
					}else if(j < c + p - 1){
						card2[j] = card1[j-c];
					}else{
						card2[j] = card1[j];
					}
				}
			}
		}
		if (r%2) cout << card2[0] << endl;
		else cout << card1[0] << endl;
	}
	return 0;
}

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

int main(){

  int card[50];
  int esc[50];
  int n,r;
  int p,c;

  while(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++){
      cin >> p >> c;

      //cout << "prev:";
      //for(int j=0; j<n; j++)cout << card[j] << ' ';
      //cout << endl;

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

      //cout << "now:";
      //for(int j=0; j<n; j++)cout << card[j] << ' ';
      //cout << endl;
      //cout << "esc:";
      //for(int j=0; j<c; j++)cout << esc[j] << ' ';
      //cout << endl;
    }

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

  return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
using namespace std;
int x[100];
int y[100];
int card [100];
int ans[100];
int n,r,counter;
bool input(){
	for(int i=0;i<100;i++){
	x[i]=0;
	y[i]=0;
	}
	cin >>n>>r;
	for(int i=0;i<r;i++){
	cin>>x[i]>>y[i];
	}
	if(n==0){
	return false;
	}
	else{
	 return true;
	}
}
void solve(){
	for(int i=0;i<100;i++){
		card[i]=i+1;
	}
	for(int i=0;i<r;i++){
		for(int k=0;k<y[i];k++){
			int a=card[x[i]+y[i]-2];
			for(int j=x[i]+y[i]-1;j>0;j--){
				card[j]=card[j-1];
			}
			card[0]=a;
		}
	}
	ans[counter]=n-card[0]+1;
	counter++;
}



int main (){
	counter=0;
	while(input()){
	solve();
	}
	for(int i=0;i<counter;i++){
	cout<<ans[i]<<endl;
	}
return 0;
}

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

#define FOR(i, a, n) for(int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

  while(true) {
    int n, r;
    int p, c;
    int temp;
    cin >> n >> r;
    if(n + r == 0) break;

    int a[100];
    REP(i, n) {
      a[i] = i + 1;
    }

    REP(i, r) {
      cin >> p >> c;
      REP(k, c) {
        FOR(j, n - p, n - 1) {
            temp = a[j - k];
            a[j - k] = a[j + 1 - k];
            a[j + 1 - k] = temp;
        }
      }
    }
    cout << a[n - 1] << endl;

  }






}

C++: #include <iostream>

using namespace std;

int main(void) {
  int yama[51], tmp[51];

  int n, r;
  while (cin >> n >> r, (n || r)) {
    // initialization
    for (int i=0; i<n; i++) {
      yama[i] = i + 1;
    }

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

      for (int j=0; j<c; j++) {
        tmp[c-1-j] = yama[n-p-j];
      }
      for (int j=n-p+1; j<n; j++) {
        yama[j-c] = yama[j];
      }
      for (int j=0; j<c; j++) {
        yama[n-c+j] = tmp[j];
      }
    }

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

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

int main(){
  int n,r;
  while(cin >> n >> r, n){
    int npos[100];
    for(int i=0;i<n;i++){
      npos[i] = n-i;
    }
    for(int i=0;i<r;i++){
      int a,b;
      cin >> a >> b;
      int tmp[b];
      for(int j=0;j<b;j++){
	tmp[j] = npos[j+a-1];
      }
      for(int j=a+b-1;j>=b-1;j--){
	npos[j] = npos[j-b];
      }
      for(int j=0;j<b;j++){
	npos[j] = tmp[j];
      }
    }
    cout << npos[0] << endl;
  }
}