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 <algorithm>

using namespace std;

int main() {
    while (true) {
        int n, r, a[50];

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

        for (int i = 0; i < n; i++) {
            a[i] = n-i;
        }

        while (r--) {
            int p, c;
            cin >> p >> c;
            rotate(a, a+p-1, a+p+c-1);
        }

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

    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int N, R, p, c;
int main() {
    while (cin >> N >> R && N) {
        vector <int> A(N,0);
        for (int i = 0; i < N; ++i) A[i] = N - i;
        for (int i = 0; i < R; ++i) {
            cin >> p >> c;
            rotate(A.begin(), A.begin()+p-1,A.begin()+c+p-1);
        }
        cout << A[0] << endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int input() {
	int input[51][2];
	cin >> input[0][0] >> input[0][1];								
	if (input[0][0] == 0 && input[0][1] == 0) {
		return 0;
	}
	for (char pos = 1; pos <= input[0][1]; pos++) {
		cin >> input[pos][0] >> input[pos][1];
	}																

	int whtop = 1;													
	whtop = input[input[0][1]][0];
	input[0][1]--;
	while (input[0][1] != 0) {

		if (input[input[0][1]][1] >= whtop) {
			whtop = input[input[0][1]][0] + whtop - 1;
		}
		else {
			whtop = whtop - input[input[0][1]][1];
		}
		input[0][1]--;
	}
	return input[0][0]-whtop+1;
}




int main()
{
	int output[1000];
	char topos = 0;
	while (1) {
		int check;
		check=input();
		if (check == 0)break;
		else {
			output[topos] = check;
			topos++;
		}
	}

	char sendpos = 0;
	while (sendpos < topos) {
		cout << output[sendpos] << endl;
		sendpos++;
	}


}

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[51];

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[51];
      for(int j=0;j<c;j++){
        tmp[j]=d[p+j-1];
      }
      for(int j=p-1;j>=0;j--){
	d[j+c]=d[j];
      }
      for(int j=0;j<c;j++){
	d[j]=tmp[j];
      }
    }
    cout<<d[0]<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
  int n,r,p,c;
  vector<int> ans;
  while(cin >> n,n){
    cin >> r;
    vector<int> v;
    for(int i = n;i > 0;i--)v.push_back(i);
    for(int i = 0;i < r;i++){
      vector<int> q(0);
      cin >> p >> c;
      for(int j = 0;j < p - 1;j++)q.push_back(v[j]);
      for(int j = p - 1;j < p + c - 1;j++)v[j - p + 1] = v[j];
      for(int j = c;j < p + c - 1;j++)v[j] = q[j - c];
    }
    ans.push_back(v[0]);
  }
  for(int i = 0;i < ans.size() - 1;i++)cout << ans[i] << endl;
  cout << ans[ans.size() - 1];
}

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

using namespace std;

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

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

int main(void){
  while(1){
    vector<int> f;
    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);
    }


    for(int i=0; i < r; i++){
      cin >> p >> c;
      vector<int> t;
      for(int j=p-1; j < p+c; j++){
        t.push_back(f.at(j));
      }
      for(int j=p-1; j > 0; j--){
        f.at(j+c) = f.at(j);
      }
      for(int j=0; j < c; j++){
        f.at(j) = t.at(j);
      }


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

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int x[1000],y[1000];
int main(){
	int n,r,a,b;
	while(true){
		cin>>n>>r;
		if(n==0 && r==0){break;}
		for(int i=1;i<=n;i++){
			x[i]=n+1-i;
		}
		for(int i=0;i<r;i++){
			cin>>b>>a;
			for(int i=b;i<a+b;i++){
				y[i-b+1]=x[i];
			}
			for(int i=1;i<b;i++){
				y[i+a]=x[i];
			}
			for(int i=a+b;i<=n;i++){
				y[i]=x[i];
			}
			for(int i=1;i<=n;i++){
				x[i]=y[i];
			}
		}
		cout<<x[1]<<endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;

int main()
{
	int n, r;
	while (cin >> n >> r, n || r) {
		vector<PII> shuffles;
		for (int i = 0; i < r; ++i) {
			int p, c;
			cin >> p >> c;
			shuffles.push_back(make_pair(p, c));
		}
		reverse(shuffles.begin(), shuffles.end());
		int index = 0;
		for (int i = 0; i < shuffles.size(); ++i) {
			int p = shuffles[i].first, c = shuffles[i].second;
			if (index < c) {
				index += p - 1;
			} else if (index < c + p - 1) {
				index -= c;
			}
		}
		cout << n - index << endl;
	}
}

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

using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define UNIQUE(o) (o).erase(unique(sort(all((o)))))

typedef long long ll;
const int N = 50;
int n, r, p, c;
int a[N][2];

int main() {
  while (1) {
    scanf("%d%d ", &n, &r);
    if (!n) break;
    REP(i,n) a[n-1-i][0] = i+1;
    int crt, nxt;
    REP(i,r) {
      crt = i&1, nxt = (i+1)&1;
      scanf("%d%d ", &p, &c);
      p--;
      REP(j,c) a[j][nxt] = a[p+j][crt];
      REP(j,p) a[j+c][nxt] = a[j][crt];
      FOR(j,p+c,n) a[j][nxt] = a[j][crt];
    }
    printf("%d\n", a[0][nxt]);
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#define REP(i,a,e) for(int i=(a);i<(e);++i)
using namespace std;
int main(){
	while(true){
		int n;
		int r;
		vector<int> v1,v2;
		cin>>n>>r;
		if(n==0&&r==0)break;
		v1.resize(n);
		REP(i,0,n){
			v1[n-1-i]=i+1;
		}
		REP(i,0,r){
			int p,c;
			cin>>p>>c;
			v2=v1;
			--p;
			v1.insert(v1.begin(),v2.begin()+p,v2.begin()+p+c);
			v1.erase(v1.begin()+c+p,v1.begin()+c+p+c);
		}
		cout << v1[0] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
  int maisu[50];
  int katto;
  int swap[50];
  int p,c;
  int i;
  for(i=0; i<50; i++){
    maisu[i] = i;
  }
  cout << maisu[0] << endl;
  cin >> katto;
  // while(j <= katto){
    while(true){
      scanf("%d%d",&p,&c);
      if(p == 0 && c == 0){break;}
      for(i=0; i<c; i++){
	swap[i] = maisu[i + p-1];
      }
      for(i = 0; i<p-1; i++){
	swap[i+c] = maisu[i];
      }
      for(i=0;i<p+c-1; i++){
	maisu[i] = swap[i];
      }
    }
    // if(p == 0 && c == 0){
	// break;
    // }
  // }
    cout << maisu[0] << endl;
    return 0;
}