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

queue<int> shuffle(queue<int>,int,int);

int main(int argc,char* argv[]){
  int n,r,p,c,val;

  while(true){
	cin >> n >> r;
	if(n == 0 || r == 0)
	  break;

	queue<int>que;
	for(int i = 1;i <= n;i++)
	  que.push(i);
	
	for(int i = 0;i < r;i++){
	  cin >> p >> c;
	  que = shuffle(que,p,c);
	}

	while(!que.empty()){
	  val = que.front();que.pop();
	}
	cout << val << endl;
  }

  return 0;
}

queue<int> shuffle(queue<int> que,int p,int c){
  queue<int> tmp;
  int n = que.size();
  for(int i = 1;i <= n;i++){
	if(i <= (n-(c+p-1)) || i > n-(p-1)){
	  que.push(que.front());
	  que.pop();
	}
	else{
	  tmp.push(que.front());
	  que.pop();
	}
  }
  while(!tmp.empty()){
	que.push(tmp.front());
	tmp.pop();
  }
  return que;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <sstream>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;

const int MAX_N = 50;
int n, r, p, c;

int cards_a[MAX_N], cards_b[MAX_N];

int main() {
    while(cin >> n, cin >> r, n != 0 && r != 0) {
        for(int i = 0; i < n; i++) cards_a[i] = n - i;

        for(int i = 0; i < r; i++) {
            cin >> p >> c;
            for(int j = 0; j < p - 1; j++) {
                cards_b[j + c] = cards_a[j];
            }
            for(int j = 0; j < c; j++) {
                cards_b[j] = cards_a[j + p - 1];
            }
            for(int j = 0; j < p + c - 1; j++) {
                cards_a[j] = cards_b[j];
            }
        }
        cout << cards_a[0] << endl;
    }

    return 0;
}

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

int main(void) {
    int n, r;
    while (cin >> n >> r, n+r) {
        vector<int> h(n);
        for (int i = 0; i < n; i++) {
            h[i] = n-i;
        }

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

            // cout << "#: ";
            // for (int j = 0; j < n; j++) {
            //     cout << " " << h[j];
            // }
            // cout << endl;
        }

        cout << h[0] << endl;
    }
    return 0;
}

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

int main()
{
	
		int n, r, c, p, i, j, k, yama[50], hikae[50];
		while (1)
		{
			cin >> n >> r;
			if (n == 0)
				break;
			for (i = 0; i < n; i++)
			{
				yama[i] = i + 1;
			}
			for (i = 0; i < r; i++)
			{
				cin >> p >> c;
				for (j = 0; j < n - p - c + 1; j++)
					hikae[j] = yama[j];
				for (k = 0; k < c; k++)
					hikae[n - k - 1] = yama[n - p - k];
				for (k = 0; k < p - 1; k++)
					hikae[n - c - k - 1] = yama[n - k - 1];
				for (j = 0; j < n; j++)
					yama[j] = hikae[j];
			}
			cout << yama[n - 1];
		}
	return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = {-1,0,1,0}; const int dy[] = {0,1,0,-1};

int main() {
	int n, r;
	while(cin >> n >> r, n|r){
		vi list(n);
		REP(i, n) list[i] = i + 1;

//		for(auto n:list)
//			LOG("%d ", n);
//		LOG("\n");

		REP(i, r){
			int p, c;
			cin >> p >> c;
			vi stk = {list.end()-(p+c-1),list.end()-(p-1)};
			list.erase(list.end()-(p+c-1),list.end()-(p-1));
			for(auto n:stk)
				list.push_back(n);

//			for(auto n:list)
//				LOG("%d ", n);
//			LOG("\n");
		}

		cout << list[list.size() - 1] << endl;
	}
}

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

int main(){

  int n, r;
  for(;cin >> n >> r, n|r;){
    vector < int > v;
    for(;n;v.push_back(n--));
    for(int p,c;r--;){
      cin >> p >> c;
      for(int tmp,q=c;q--;){
	tmp = v[p+c-2];
	v.erase(v.begin()+p+c-2);
	v.insert(v.begin(), tmp);
      }
    }

    cout << v[0] << endl;
  }

}

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

using namespace std;

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

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

int main()
{
	int n, r, p, c;
	
	while(cin >> n >> r && n>0)
		{
			//山を作る
			int A[n];
			for(int i = 0; i<n; i++){ A[i] = n-i; }
			
			//表示
			//for(int i = 0; i<n; i++){ cout << A[i] << " "; }
			//cout << endl;
			
			for(int i = 0; i<r; i++)
			{
				cin >> p >> c;
				rotate(&A[0], &A[p-1], &A[p+c-1]);
				
				//表示
				//for(int i = 0; i<n; i++){ cout << A[i] << " "; }
				//cout << endl;
			}
			cout << A[0] << endl;
		}
}

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

int main () {
  int n, r;
  while(true){
    cin >> n >> r;
    if(n == 0 && r == 0) break;
    else{
      stack <int> l1, l2, l3;
      while(!l1.empty()) l1.pop();
      int p, c;
      for(int j = 0;j < n; j++) {
        l1.push(j + 1);
      }
      for(int i = 0; i < r; i++) {
        cin >> p >> c;
        for(int j = 0;j < p - 1; j++) {
          l2.push(l1.top());
          l1.pop();
        }
        for(int j = 0;j < c; j++) {
          l3.push(l1.top());
          l1.pop();
        }
        for(int j = 0;j < p - 1; j++) {
          l1.push(l2.top());
          l2.pop();
        }
        for(int j = 0;j < c; j++) {
          l1.push(l3.top());
          l3.pop();
        }
      }
      cout << l1.top() << endl;
    }
  }
  return 0;
}