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 <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>
#include <algorithm>
#include <vector>
using namespace std;

#define repeat(i, n) for(int i = 0; i < (n); i++)

int main() {
    int n, r;
    while (cin >> n >> r) {
        if (n == 0 && r == 0) break;
        vector<int> pile(n);
        repeat(i, n) {
            pile[i] = n-i;
        }
        repeat(i, r) {
            int p, c; cin >> p >> c;
            vector<int> after(n);
            repeat(j, p-1) {
                after[j+c] = pile[j];
            }
            for (int j = p-1; j < p+c-1; j++) {
                after[j-p+1] = pile[j];
            }
            pile = after;
        }
        cout << pile[0] << endl;
    }
    return 0;
}

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

int main(){
  int n, r;
  cin >> n >> r;

  int p, c;
  while(n != 0 && r != 0){
    vector<int> v(n);
    vector<int> v1(n);
    for(int i = 0; i < n; i++){
      v[i] = n - i;
    }

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

      for(int j = 0; j < n; j++){
        v1[j] = v[j];
      }

      for(int j = 0; j < c; j++){
        v[j] = v1[p + j];
      }

      for(int j = c; j < p + c; j++){
        v[j] = v1[j - c];
      }
        
      for(int j = 0; j < n; j++){
        //cerr << v[j] << " ";
      }
      //cerr << endl;
    }
    cout << v[0] << endl;
    cin >> n >> r;
  }

}

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

using namespace std;

int solve(int n,int r)
{
	if(r==0) return n;
	int p,c; cin>>p>>c;
	int x=solve(n,r-1);
	if(x>n-c)
		x-=(p-1);
	else if(n-c>=x && x>n-p-c+1)
		x+=c;
	return x;
}

int main()
{
	for(int n,r;cin>>n>>r,n|r;)
		cout<<solve(n,r)<<endl;
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int n, r, p, c;
	int cards[50], tmp[50];
	
	cin >> n >> r;

	while (n != 0 && r != 0) {
		for (int i = 0; i < n; i++) cards[i] = n - i;
		for (int i = 0; i < r; i++) {
			cin >> p >> c;
			for (int j = 0; j < p - 1; j++) tmp[j] = cards[j];
			for (int j = 0; j < c; j++) cards[j] = cards[p - 1 + j];
			for (int j = 0; j < p - 1; j++) cards[c + j] = tmp[j];
		}

		cout << cards[0] << endl;

		cin >> n >> r;
	}
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,R;
    cin >> N >> R;
    while(N){
        vector<int> V(N);
        iota(V.rbegin(), V.rend(), 1);
        for(auto i:V)cout << i << endl;
        rep(i,0,R){
            int p,c;
            cin >> p >> c;
            vector<int> tmp(p + c - 1);
            rep(j,0,c){
                tmp[j] = V[j + p - 1];
            }
            rep(j,c,p+c-1){
                tmp[j] = V[j-c];
            }
            rep(j,0,p+c-1){
                V[j] = tmp[j];
            }
        }
        cout << V[0] << endl;
        cin >> N >> R;
    }
}

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl;
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// Aliases
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int main() {
    while(true) {
        int n, r;
        cin >> n >> r;
        if(n == 0 && r == 0) break;
        int loc = 1;
        stack<pair<int, int>> st;
        REP(i, r) {
            int p, c;
            cin >> p >> c;
            st.push(pair<int, int>(p, c));
        }
        while(!st.empty()) {
            auto ro = st.top();
            st.pop();
            if(ro.second >= loc) {
                loc += ro.first - 1;
            }
            else if(ro.first + ro.second > loc) {
                loc -= ro.second;
            }
        }
        cout << n - loc + 1 << "\n";
    }

    return 0;
}

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

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