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<vector>
#include<algorithm>

using namespace std;

vector<int>card;

void cut(int p,int c){
  vector<int>res;
  for(int i=p;i<p+c;i++)res.push_back(card[i]);
  for(int i=0;i<p;i++)res.push_back(card[i]);
  for(int i=p+c;i<card.size();i++)res.push_back(card[i]);
  card=res;
}

int main(void){
  int n,r;

  while(cin >> n >> r, n|r){
    card.resize(n);
    for(int i=0;i<n;i++)card[i]=n-i;
    
    int p,c;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      cut(p-1,c);
    }
    cout << card[0] << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
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;
		}

		for (int i = 0; i < r; i++){
			int p, c, b[50];
			cin >> p >> c;
			for (int j = 0; j < p-1; j++){
				b[j] = a[j];
			}
			for (int j = 0; j < c; j++){
				a[j] = a[p + j-1];
			}
			for (int j = 0; j < p-1; j++){
				a[c + j] = b[j];
			}
		}

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

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = 998244353LL;
const double pi = acos(-1.0);

void re(VI & v, int p, int c) {
	VI P, C;
	rep(i, p - 1)P.pb(v[i]);
	FOR(i, p - 1, p + c - 1)C.pb(v[i]);
	rep(i, sz(C))v[i] = C[i];
	FOR(i, c, p + c - 1)v[i] = P[i - c];
}

int main() {
	int n, r;
	while (cin >> n >> r && (n || r)) {
		VI a(n); rep(i, n)a[i] = n - i;
		rep(i, r) {
			int p, c; cin >> p >> c;
			re(a, p, c);
		}
		Cout(a[0]);
	}
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int input(char s[]);

int main() {
	int cnt,ans[10000],n, r,brk=0,p,c,x[50],xs[50];
	for (int i = 0; i < 50; i++)
		x[i] = xs[i] = i;

	//while (1) {
	for (cnt=0; cnt<10000; cnt++) {
		scanf("%d %d", &n, &r);
		if (n == 0 && r == 0)
			brk = 1;
		if (brk == 1)
			break;
		for (int i = 0; i < r&&brk == 0; i++) {
			scanf("%d %d", &p, &c);
			for (int j = 0; j < c; j++)
				x[j] = xs[j + p - 1];
			for (int j = c; j < c + p - 1; j++)
				x[j] = xs[j - c];
			for (int j = 0; j < n; j++)
				xs[j] = x[j];}
			ans[cnt] = n - x[0];
	}
	for (int i = 0; i < cnt; i++)
		printf("%d\n", ans[i]);
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#ifndef repeat
#define repeat(i,n) for (int i = 0; i < (n); ++i)
#endif
#ifndef repeat_from
#define repeat_from(i,m,n) for (int i = (m); i < (n); ++i)
#endif
#ifndef repeat_one
#define repeat_one(i,n) for (int i = 1; i <= (n); ++i)
#endif
#ifndef repeat_rev
#define repeat_rev(i,n) for (int i = (n)-1; 0 <= i; --i)
#endif
#ifndef foreach
#define foreach(it, cont) for (typeof(cont.begin()) it = cont.begin(); it != cont.end(); ++it)
#endif
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    while (true) {
        int n, r; cin >> n >> r;
        if (n == 0 and r == 0) break;
        vector<int> v(n); repeat (i,n) v[i] = n-i;
        repeat (i,r) {
            int p, c; cin >> p >> c;
            vector<int> vp(v.begin(),   v.begin()+p-1);
            vector<int> vc(v.begin()+p-1, v.begin()+p-1+c);
            copy(vp.begin(), vp.end(), v.begin()+c);
            copy(vc.begin(), vc.end(), v.begin());
        }
        cout << v.front() << endl;
    }
    return 0;
}

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[1000];
  int r[1000];
  int p[1000][200];
  int c[1000][200];
  int c_tmp[1000][200];
  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>

using namespace std;

int data[50], n, r, p, c, tmp[50], next[50];

main(){
  while(cin >> n >> r && (n|r)){
    for(int i=0;i<n;i++) data[i] = n-i;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      for(int j=0;j<p-1;j++) tmp[j] = data[j];
      for(int j=0;j<c;j++) next[j] = data[p-1+j];
      for(int j=0;j<p-1;j++) next[c+j] = tmp[j];
      for(int j=0;j<p+c;j++) data[j] = next[j];
    }
    cout << data[0] << endl;
  }
}

C++: #include <cstdio>

using namespace std;

int n, r;
// greater is upper
int D[51];
int X[51];

int main() {
    for (;;) {
        scanf("%d%d", &n, &r);
        if (!n && !r) { break; }

        for (int i = 1; i <= 50; i++) {
            D[i] = i;
        }

        for (int i = 0; i < r; i++) {
            int p, c;
            scanf("%d%d", &p, &c);
            for (int j = 0; j < c; j++) {
                X[j] = D[n - (p - 1) - c + 1 + j];
            }
            for (int j = 0; j < p - 1; j++) {
                D[n - (p - 1) - c + 1 + j] = D[n - (p - 1) - c + 1 + j + c];
            }
            for (int j = 0; j < c; j++) {
                D[n - c + 1 + j] = X[j];
            }
        }

        printf("%d\n", D[n]);
    }
    return 0;
}