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(){
    int n,r;
    while(cin>>n>>r,n){
        vector<int> hana,array;
        for(int i=n;i>=1;i--){
            hana.push_back(i);
        }
        for(int i=0;i<r;i++){
            int p,c;
            cin>>p>>c;
            for(int j=0;j<c;j++){
                array.push_back(hana[p-1+j]);
            }
            for(int j=p-2;j>=0;j--){
                hana[j+c]=hana[j];
            }
            hana=array;
            array.clear();
        }
        cout<<hana[0]<<endl;
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#define INF 100000000

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

static const double EPS = 1e-8;

const int tx[] = {0,1,0,-1};
const int ty[] = {1,0,-1,0};

int main(){
	int n,r;
	while(~scanf("%d %d",&n,&r)){
		if(n==r && r==0) break;
		vector<int> pile;
		for(int i=n;i>=1;i--){
			pile.push_back(i);
		}
		for(int i=0;i<r;i++){
			int p,c;
			scanf("%d %d",&p,&c);

			vector<int> tmp;
			for(int j=p-1;j<p+c-1;j++){
				tmp.push_back(pile[j]);
			}

			for(int j=0;j<p-1;j++){
				tmp.push_back(pile[j]);
			}

			for(int j=p+c-1;j<n;j++){
				tmp.push_back(pile[j]);
			}

			pile = tmp;
		}

		printf("%d\n",*pile.begin());
	}
}

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

using namespace std;

int main()
{
	int n, r;

	while (scanf("%d %d", &n, &r), n){
		vector<int> v;

		for (int i = 0; i < n; i++){
			v.push_back(n - i);
		}

		for (int i = 0; i < r; i++){
			int p, c;

			scanf("%d %d", &p, &c);

			stack<int> s;

			for (int j = p - 1; j < p + c - 1; j++){
				s.push(v[j]);
				v[j] = 0;
			}

			for (int j = n - 1; j > 0; j--){
				if (v[j] == 0){
					v[j] ^= v[j - 1];
					v[j - 1] ^= v[j];
					v[j] ^= v[j - 1];
				}
			}

			for (int j = c - 1; j >= 0; j--){
				v[j] = s.top();
				s.pop();
			}
		}

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

	return (0);
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it = (c).begin(); it != (c).end(); it++)
#define X first
#define Y second

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
    for(int n, r; cin >> n >> r, n;){
        string y;
        rep(i, n) y.pb('0' + n - i);

        while(r--){
            int p, c; cin >> p >> c;

            string str1 = y.substr(p - 1, c);
            string str2 = y.substr(0, p - 1);
            string str3 = y.substr(p + c - 1);
            y = str1 + str2 + str3;
        }

        cout << (int)(y.at(0) - '0') << endl;
    }

    return 0;
}

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

void cut(vector<int>& a, int p, int c) {
  vector<int> ptemp(p), ctemp(c);
  for (int i = 0; i < p; i++) {
    ptemp[i] = a[i];
  }
  for (int i = 0; i < c; i++) {
    ctemp[i] = a[p + i];
  }
  for (int i = 0; i < c; i++) {
    a[i] = ctemp[i];
  }
  for (int i = 0; i < p; i++) {
    a[i + c] = ptemp[i];
  }/*
  for (int i = 0; i < a.size();i++){
    printf("%2d", a[i]);
  }
  cout << endl;
  */
  return;
}

int main() {
  int n, r;
  while (1) {
    cin >> n >> r;
    if (n == 0) {
      break;
    }
    vector<int> a(n);
    iota(a.rbegin(), a.rend(), 1);
    // cout << a[0] << " " << a[1] << " " << a[2] << endl;
    int p, c;
    for (int i = 0; i < r; i++) {
      cin >> p >> c;
      p--;
      cut(a, p, c);
    }
    cout << a[0] << endl;
  }
  return 0;
}

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

using namespace std;

void cut(int *a, int p, int c)
{
    for(int i=0; i<c; i++)
    {
        int t = a[p+i];
        for(int j=p+i; j>i; j--)
        {
            a[j] = a[j-1];
        }
        a[i] = t;
    }
}

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

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

int main(){
	while(1){
		int n,r,p,c,s[n + 1];
		cin >> n >> r;
		if(n == 0 && r ==0)break;
		for(int i = 1; i <= n;++i){
			s[i] = i;
			}
			for(int j = 1; j <= r;++j){
				cin >> p >> c;
			    for(int k = 1;k <=c;++k){
			    		s[0] = s[n - p - c + 2];
				    for(int l = 0;l <= p + c - 3;++l){
					    s[n - p - c + 2 + l] = s[n - p - c + 3 + l];
					}
					s[n] = s[0];
			    }
		     }
		  cout << s[n] << endl;
	}
	return 0;
}

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

using namespace std;
int n, r, p, c;

int main(){
	while (cin >> n >> r && n){
		int a[n];
		for (int i = 0; i < r; i++){
			a[n-i-1] = i + 1;
		}
		for (int j = 0; j < r; j++){
			rotate(a, a + p-1, a + p + c-1);
		}
		cout << a[0] << endl;
	}
	return 0;
}

C++: #include <cstdio>

using namespace std;

void cut(int a[], int p, int c)
{
    int b[50];

    for (int i = 0; i < c; ++i)
        b[i] = a[p - 1 + i];
    for (int i = 0; i < p - 1; ++i)
        a[p - 1 + c - 1 - i] = a[p - 1 - 1 - i];
    for (int i = 0; i < c; ++i)
        a[i] = b[i];
}

int main()
{
    for (;;) {
        int n, r, a[50];

        scanf("%d %d", &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;

            scanf("%d %d", &p, &c);
            cut(a, p, c);
        }

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

    return 0;
}