Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		n, _ := strconv.Atoi(chunks[0])
		r, _ := strconv.Atoi(chunks[1])
		cards := make([]int, n, n)
		for i := 0; i < n; i++ {
			cards[i] = n - i
		}
		for i := 0; i < r; i++ {
			sc.Scan()
			chunks := strings.Split(sc.Text(), " ")
			p, _ := strconv.Atoi(chunks[0])
			c, _ := strconv.Atoi(chunks[1])
			block := make([]int, c, c)
			for j := 0; j < c; j++ {
				block[j] = cards[p+j-1]
			}
			for j := p - 2; j >= 0; j-- {
				cards[j+c] = cards[j]
			}
			for j := 0; j < c; j++ {
				cards[j] = block[j]
			}
		}
		fmt.Println(cards[0])
	}
}

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

using namespace std;

int main(void) {
  int n, r;
  while (cin >> n >> r && n + r) {
    auto deck = vector<int>(n);
    for (int i = 0; i < n; i++) deck[i] = n-i;
    for (int i = 0; i < r; i++) {
      int p, c; //3 1
      cin >> p >> c;
      auto temp = vector<int>(c);
      for (int j = 0; j < c; j++) temp[j] = deck[p-1+j];
      for (int j = c+p-2; j >= c; j--) deck[j] = deck[j-c];
      for (int j = 0; j < c; j++) deck[j] = temp[j];
    }
    cout << deck[0] << endl;
  }
}

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

int n, r;
int p[64], c[64];

int main() {
  for(;;) {
    scanf("%d %d", &n, &r);
    if( n == 0 and r == 0 ) break;
    for(int i = 0; i < r; ++i) {
      scanf("%d %d", &p[i], &c[i]);
    }
    int res = n;
    for(int i = r - 1; i >= 0; --i) {
      if( n - c[i] < res ) {
        res -= p[i] - 1;
      }
      else if( n - c[i] - (p[i] - 1) < res and res <= n - c[i] ) {
        res += c[i];
      }
    }
    printf("%d\n", res);
  }

  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,r;
    while(cin>>n>>r,n||r){
        vector<int>V[2];
        V[0].resize(n);
        for(int i=0;i<n;i++)V[0][i]=n-i;
        int p,c;
        for(int i=0;i<r;i++){
            cin>>p>>c;
            V[(i+1)&1].clear();
            for(int j=p-1;j<p+c-1;j++)
                V[(i+1)&1].push_back(V[i&1][j]);

            for(int j=0;j<p-1;j++)
                V[(i+1)&1].push_back(V[i&1][j]);
            for(int j=p+c-1;j<n;j++)
                V[(i+1)&1].push_back(V[i&1][j]);
           ///for(int j=0;j<n;j++)cout<<V[(i+1)&1][j]<<" ";
           // cout<<endl;
        }
        cout<<V[r&1][0]<<endl;
    }
}

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

int main(void)
{
    int n,r,p,c;
    int a[200], b[200];
    while(1) {
        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++) {
            cin >> p >> c;
            for(int j=p-1; j<(p-1)+c; j++) {
                b[j-(p-1)] = a[j];
            }
            for(int j=0; j<n; j++) {
                if(j < p-1 && j > p-1+c)
                    b[j+(p-1)] = a[j];
            }
            for(int j=0; j<n; j++) {
                a[j] = b[j];
            }
            cout << a[0] << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#define N 50
using namespace std;
int main(){
	int n, r, p, c, i, j, card[N+1], memo[N+1];
	while(cin >> n >> r, n){
		for(i = 1; i <= n; i++) card[i] = n - i + 1;
		for(i = 0; i < r; i++){
			cin >> p >> c;
			for(j = 1; j < p; j++) memo[j] = card[j];
			for(j = 1; j <= c; j++) card[j] = card[p + j - 1];
			for(j = 1; j < p; j++) card[c + j] = memo[j];
		}
	cout << card[1] << endl;
	}
	return 0;
}

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

int p[60], c[60];

int main(){
    int n, r;
    while(cin >> n >> r && (n | r)){
        for(int i=0;i<r;i++)
            cin >> p[i] >> c[i];
        
        int target = 1;
        for(int i=r-1;i>=0;i--){
            int t = p[i] - 1 + c[i];
            
            if(target > t)
                continue;
        
            if(target <= c[i]){
                target = p[i] - 1 + target;
            } else {
                target = target - c[i];
            }
        }
        
        cout << n + 1 - target << endl;
    }
    
    return 0;
}

C++: #include<iostream>
#include<algorithm>

using namespace std;
int N,R,p,c;

int main() {
	while (cin >> N >> R && N) 
	{
		//		cout << N <<  " " << R << endl;
		int M[N];
		for (int i = 0; i < N; ++i)
		{
			M[i] = N-i;
		}
		//for (int i = 0; i < N; ++i)
		//{
		//	cout << M[i] << endl;
		//}
		for (int i = 0; i < R; ++i)
		{
			cin >> p >> c;
			rotate(M,M+p-1,M+p+c-1);
		//			cout << p << " " << c << endl;
		}
		cout << M[0] << endl;
	}
}

C++: #include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

vector<int> ans;

int solve(int n, int r){
    vector<int> cards(n);
    for (int i = n-1; i >= 0; i--){
        cards[i] = n-i;
    }

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


int main(){
    cin.tie(0);

    while (1){
        int N, R; cin >> N >> R;
        if (!N && !R) break;
        ans.push_back(solve(N, R));
    }
    for (auto itr = ans.begin(); itr != ans.end(); itr++){
        cout << *itr << endl;
    }
}

C++: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M;
	while (N) {
		long long int num[50] = {};
		for (int i = 0; i < N; i++) {
			num[i] = (N-i) * MOD + i + 1;
		}
		for (int i = 0; i < M; i++) {
			cin >> K >> Q;
			for (int j = 0; j < N; j++) {
				if (num[j] % MOD < K) {
					num[j] += Q;
				}
				else if (num[j] % MOD < K + Q) {
					num[j] -= (K - 1);
				}
			}
		}
		for (int i = 0; i < N; i++) {
			if (num[i] % MOD == 1)cout << num[i] / MOD << endl;
		}
		cin >> N >> M;
	}
	return 0;
}