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 and macros
#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(a, b) for(int unsafe_cnt=a; unsafe_cnt < b;unsafe_cnt++)
#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;
// }}}

// {{{ put
void newline() {cout << endl;}
template <typename T> void display(T input){cout << input;}
template <typename T> void put(T input){display(input); newline();}
// }}}

vector<int> to_top(const vector<int> v
                  ,const int p   // ???????§????
                  ,const int c){
  vector<int> w;
  for(int i=p; i<p+c; i++){
    w.push_back(v[i]);
  }
  for(int i=0; i<v.size(); i++){
    if(!(p<=i && i<p+c)){
      w.push_back(v[i]);
    }
  }
  return w;
}

int main() {
  int n, r;
  while(cin >> n >> r && n){
    vector<int> v;
    for(int i=n; i > 0; i--){v.push_back(i);}
    // for(int i=0;i<v.size();i++){display(v[i]);display(" ");} put("");
    for(int i=0; i < r; i++){
      int p, c;
      cin >> p >> c;
      v = to_top(v, p-1, c);
      // for(int i=0;i<v.size();i++){display(v[i]);display(" ");}put("");
    }
    put(v[0]);
  }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n, r;
	while (cin >> n >> r, n)
	{
		int a[51];
		for (int i = 1;i <= n;i++)a[i] = n - i + 1;
		for (int i = 0;i < r;i++)
		{
			int p, c;cin >> p >> c;
			int b[51];
			for (int j = 1;j < p;j++)b[j] = a[j];
			for (int j = p;j < p + c;j++)a[j - p + 1] = a[j];
			for (int j = 1;j < p;j++)a[c + j] = b[j];
		}
		cout << a[1] << endl;
	}
}

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

void hanafudaShuffle(int p, int c, int n, int* cards) {
    int* cutCards = new int [c];
    for (int i = 0; i < c; i++) {
        cutCards[i] = cards[p - 1 + i];
    }
    for (int i = p - 2; i >= 0; i--) {
        cards[c + i] = cards[i];
    }
    for (int i = 0; i < c; i++) {
        cards[i] = cutCards[i];
    }
    delete[] cutCards;
}

int main() {
    while (true) {
        int n, r;
        cin >> n >> r;
        if ((n | r) == 0) {
            break;
        }
        int* cards = new int [n];
        for (int i = 0; i < n; i++) {
            cards[i] = n - i;
        }
        for (int i = 0; i < r; i++) {
            int p, c;
            cin >> p >> c;
            hanafudaShuffle(p, c, n, cards);
        }
        cout << cards[0] << endl;
        delete[] cards;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 128;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

int v[MAX];

void solve(void){
    while (1) {
        int n, r;
        scanf("%d %d\n", &n, &r);
        if (n == 0 && r == 0) break;
        rep(n, i) v[i] = n-i;
        rep(r, meaningless_) {
            int vv[n];
            rep(n, i) vv[i] = v[i];
            int p, c;
            scanf("%d %d\n", &p, &c);
            rep(c, j) {
                v[j] = vv[p-1+j];
            }
            rep(p-1, j) {
                v[c+j] = vv[j];
            }
        }
        printf("%d\n", v[0]);
    }
}

int main(void){
  solve();
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)

int main(){
  int n, r;
  while(cin >>n >>r && n){
    vector<int> v;
    for(int i = n; i > 0; i--) v.push_back(i);

    rep(i, r){
      int p, c;
      cin >>p >>c;
      vector<int> next;
      for(int i = 0; i < c; i++) next.push_back(v[p - 1 + i]);
      for(int i = 0; i < p - 1; i++) next.push_back(v[i]);
      for(int i = p + c - 1; i < v.size(); i++) next.push_back(v[i]);
      v = next;
    }
    cout <<v[0] <<endl;
  }
  return 0;
}

C++: #include<stdio.h>

int main(){
	int a[52],b[52],p,c,i,j,n,r;
	while(1){
		scanf("%d %d",&n,&r);
		if(n==0&&r==0)break;
		for(i=1;i<=n;i++)a[i-1]=n-i+1;
		while(r--){
			//for(i=0;i<n;i++)printf("%d ",a[i]);
			//printf("\n");
			scanf("%d %d",&p,&c);
			for(i=0;i<c;i++)b[i]=a[p+i-1];
			for(i=p-2;i>=0;i--)a[i+c]=a[i];
			for(i=0;i<c;i++)a[i]=b[i];
		}
		printf("%d\n",a[0]);
	}
	return 0;
}

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

int main(void)
{
	while ( true ) {
		std::vector<int> yama;
		int n, r;

		std::cin >> n;
		std::cin >> r;

		if ( n == 0 && r == 0 ) break;

		yama.resize(n);

		for ( int i = 0; i < n; ++i ) {
			yama[i] = i + 1;
		}

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

			int b = n - p;

			std::vector<int> d(c);

			for ( int j = 0; j < c; ++j ) {
				d[c - j -1] = yama[b - j];
			}

			for ( int j = b; j < n; ++j ) {
				yama[j - c] = yama[j];
			}

			for ( int j = n - c; j < n; ++j ) {
				yama[j] = d[j - n + c];
			}
			for ( int i = 0; i < n; ++i ) {
				std::cout << yama[i] << std::endl;
			}
		}

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

C++: #include<cstdio>

using namespace std;

int main(){
	for(int n,r;scanf("%d%d",&n,&r),n;){
		int q=0;
		while(r--){
			int p,c; scanf("%d%d",&p,&c);
			if     (q<c)     q+=p-1;
			else if(q<c+p-1) q-=c;
		}
		printf("%d\n",n-q);
	}

	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,r,c,p;
    vector<int> s,s2;
    while(1){
        cin >> n >> r;
        if(n==0&&r==0)  break;
        for(int i=1;i<=n;i++){
            s.push_back(i);
        }
        while(r--){
            cin >> p >> c;
            for(int i=0;i<n-c-p+1;i++){
                s2.push_back(s[i]);
            }
            for(int i=n-p+1;i<n;i++){
                s2.push_back(s[i]);
            }
            for(int i=n-c-p+1;i<n-p+1;i++){
                s2.push_back(s[i]);
            }
            s.clear();
            for(int i=0;i<n;i++){
                s.push_back(s2[i]);
            }
            s2.clear();
        }
        cout << s[n-1] << "\n";
        s.clear();
    }
}