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<stdio.h>

int main() {

	int n, r;
	int array[51];
	int tmp[51];
	while (1) {
		scanf("%d %d", &n, &r);
		if (n == 0 && r == 0) break;

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

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

int main(){
  int n,r, start, end;
  vector<int> ans;
  cin >> n >> r;
  while(n||r){
    vector<int> data(n);
    for(int i = 0; i <n;i++){
      data[i] = n-i;
    }
    for(int j = 0; j < r ; j++){
      cin >> start >> end;
      for(int k = 0; k < end;k++){
        int a = data[start+k-1];
        for(int forth = start-1; forth > k; forth--){
          data[k+forth+1] = data[k+forth];
        }
        data[k] = a;
      }
    }
    ans.push_back(data[0]);
    cin >> n >> r;
  }
  for(int i =0;i<(int)ans.size();i++){
    cout << ans[i] << endl;
  }
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
  int ocs[100], ods[100];
  for(int t = 1;; t++) {
    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 - 1; j < n; j++) {
        ds[j] = cs[j];
      }
      int *tmp = cs;
      cs = ds;
      ds = tmp;
    }
    cout << cs[0] << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 n, r;
  while(cin >> n >> r, n && r) {
    vector<i64> a(n);
    rep(i,0,n) {
      a[i] = n - i;
    }
    rep(R, 0, r) {
      i64 p, c;
      cin >> p >> c;
      p--;
      vector<i64> tmp(c);
      rep(i,0,c) {
        tmp[i] = a[p + i];
      }
      for(i64 i = p - 1;i >= 0;i--) {
        a[i + c] = a[i];
      }
      rep(i,0,c) {
        a[i] = tmp[i];
      }
    }
    cout << a.front() << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
	int n,m;
	while(cin>>n>>m,n,m){
		string str;
		for(int i=n,j=0;j<n;i--,j++)str+=i-'0';
		for(int i=0,p,c;i<m;i++){
			string now;
			cin>>p>>c;
			for(int j=0;j<c;j++)now+=str[p-1+j];
			for(int j=0;j<n;j++)if(j<p-1||j>p+c-1)now+=str[j];
			str=now;
		}
		cout<<str[0]+'0'<<endl;
	}
}

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

using namespace std;

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

	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define REEP(i, N) for(ll i = N - 1; i >= 0; --i)
#define FOR(i,m,n) for(ll i = m; i < n; ++i)
#define RFOR(i,m,n) for(ll i = n - 1; i >= m; --i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define PB push_back
#define KIRIAGE(a, b) a += (b - a % b) % b // a ??? b ????????°????????§?¢???????
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;} // a / b ??\??????????°???´??°
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	while(true) {
		int n, r;
		cin>>n>>r;
		vector<ll> card(n);
		REP(i, n) {
			card[i] = n - i;
		}
		if(n==0&&r==0) return 0;
		REP(i, r) {
			int p, c;
			cin>>p>>c;
			vector<ll> hoge(p - 1);
			REP(i, p - 1) hoge[i] = card[i];
			REP(i, c) card[i] = card[p - 1 + i];
			REP(i, p - 1) card[c + i] = hoge[i];
		}
		cout<<card[0]<<endl;
	}
}

C++: #include <cstdio>
#include <iostream>
using namespace std;
int n,r;
int c[2][55];
int main(void){
  while(cin >> n >> r && n){
    for(int i = 0; i < n; i++) c[0][n-i-1] = i+1;
    for(int i = 0; i < r; i++){
      int a,b;
      cin >> a >> b;
      a--;
      for(int j = 0; j < b; j++)
	c[(i+1)%2][j] = c[i%2][a+j];
      for(int j = 0; j < a; j++)
	c[(i+1)%2][b+j] = c[i%2][j];
      for(int j = a+b; j < n; j++)
	c[(i+1)%2][j] = c[i%2][j];

      /*
      for(int j = 0; j < n; j++)
	cout << c[(i+1)%2][j] << " ";
      cout << endl;
      */
    }
    cout << c[r%2][0] << endl;
  }
}

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

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

		vector<int> card;
		vector<int> card2;
		for(int i=n; i>0; i--){
			card.push_back(i);
		}

		for(int i=0; i<r; i++){
			int p, c;
			cin >> p >> c;
			p--;
			for(int j=p; j<p+c; j++){
				card2.push_back(card[j]);
			}
			for(int j=0; j<p; j++){
				card2.push_back(card[j]);
			}
			for(int j=p+c; j<n; j++){
				card2.push_back(card[j]);
			}
			card = card2;
			card2.clear();

			/*
			for(int j=0; j<n; j++){
				printf("%d ", card[j]);
			}
			puts("");
			*/
		}

		cout << card[0] << endl;



	}


	return 0;
}

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

int main() {
	int n, r, p, c;
	while (cin >> n >> r , n != 0 || r != 0) {
		vector<int> deck = vector<int>(n);
		for (int i = 0; i < n; i++) {
			deck[i] = n - i;
		}

		for (int j = 0; j < r; j++) {
			cin >> p >> c;
			vector<int> tmp = vector<int>(c);
			for (int k = 0; k < c; k++) {
				tmp[k] = deck[p - 1 + k];
			}
			for (int k = 0; k < p - 1; k++) {
				deck[p + c - 2 - k] = deck[p - 2 - k];
			}
			for (int k = 0; k < c; k++) {
				deck[k] = tmp[k];
			}
		}
		cout << deck[0] << endl;
	}


}