Go: package main

import "fmt"

func main() {
	var n, r int
	fmt.Scan(&n, &r)
	for n != 0 || r != 0 {
		arr := make([]int, n)
		for i := range arr {
			arr[i] = len(arr) - i
		}

		for i := 0; i < r; i++ {
			var p, c int
			fmt.Scan(&p, &c)
			mid, top, last := arr[:p-1], arr[p-1:p-1+c], arr[p-1+c:]
			arr = append(append(append([]int{}, top...), mid...), last...)
		}
		fmt.Println(arr[0])
		fmt.Scan(&n, &r)
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true)
    {
        int n, r;
        cin >> n >> r;
        if (n == 0 && r == 0)
        {
            break;
        }
        vector<int> hanahuda;
        for (int i = n; i >= 1; i--)
        {
            hanahuda.push_back(i);
        }
        for (int i = 0; i < r; i++)
        {
            vector<int> tmp1, tmp2, tmp3;
            int p, c;
            cin >> p >> c;
            for (int j = 0; j < p - 1; j++)
            {
                tmp2.push_back(hanahuda[j]);
            }
            for (int j = p - 1; j < p + c - 1; j++)
            {
                tmp1.push_back(hanahuda[j]);
            }
            for (int j = p + c - 1; j < n; j++)
            {
                tmp3.push_back(hanahuda[j]);
            }
            hanahuda.clear();
            for (int i = 0; i < (int)tmp1.size(); i++)
            {
                hanahuda.push_back(tmp1[i]);
            }
            for (int i = 0; i < (int)tmp2.size(); i++)
            {
                hanahuda.push_back(tmp2[i]);
            }
            for (int i = 0; i < (int)tmp3.size(); i++)
            {
                hanahuda.push_back(tmp3[i]);
            }
        }
        cout << hanahuda[0] << endl;
    }
}

C++: #include <iostream>

using namespace std;

int main(){
  int n, r;
  int card[50];
  int cutp[50];
  int cutc[50];

  while(cin >> n >> r, n || r){
    for(int i=0; i<n; i++){
      card[i] = i+1;
    }
    for(int j=0; j<r; j++){
      int p, c;
      cin >> p >> c;
      for(int i=0; i<p-1; i++){
	cutp[i] = card[n-p+1+i];
      }
      for(int i=0; i<c; i++){
	cutc[i] = card[n-p+1-c+i];
      }
      
      for(int i=0; i<p-1; i++){
	card[n-p+1-c+i] = cutp[i];
      }
      for(int i=0; i<c; i++){
	card[n-c+i] = cutc[i];
      }
    }

    cout << card[n-1] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int N,R,p,c;
int main() {
  while(cin >> N >> R && N>0){
    vector<int> a(N);
    for(int i=0;i<N;i++){
      a[i] = N-i;
      //cout << a[i] << endl;
    }
    for (int i=0; i<R;++i){
      cin >> p >> c;
      rotate(a.begin(),a.begin()+p-1,a.begin()+p-1+c);
      for(int j=0;j<a.size(); j++){
	//cout << a[j] << endl;
      }
    }
    cout << a[0] << endl;
  }
}

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

using namespace std;

int main()
{
    int n, r;
    int p, c;
    r = 0;
    vector<int> card;
    vector<int> reserve;
    while (true) {
        if (r == 0) {
            cin >> n >> r;
            if (n == 0 && r == 0)
                break;
            for (int i = 0; i < n; i++) {
                card.push_back(i + 1);
            }
            continue;
        }
        cin >> p >> c;
        for (int i = n - p + 1; i < n; i++) {
            reserve.push_back(card.at(i));
        }
        for (int i = n - (p - 1) - c; i < n - (p - 1); i++) {
            reserve.push_back(card.at(i));
        }
        {
            int j = 0;
            for (int i = n - (p - 1) - c; i < n; i++) {
                card.at(i) = reserve.at(j);
                j++;
            }
        }
        reserve.clear();
        reserve.shrink_to_fit();
        r--;
        if (r == 0) {
            cout << card.at(n - 1) << endl;
            card.clear();
            card.shrink_to_fit();
        }
    }
}

C++: #include <stdio.h>
int n, r, p, c, d[50], e[50];
int main() {
	while (true) {
		scanf("%d%d", &n, &r);
		if (n == 0 && r == 0) break;
		for (int i = 0; i < n; i++) d[i] = n - i;
		for (int i = 0; i < r; i++) {
			scanf("%d%d", &p, &c); p--;
			for (int j = 0; j < c; j++) {
				e[j] = d[j + p];
			}
			for (int j = c; j < p + c; j++) {
				e[j] = d[j - c];
			}
			for (int j = 0; j < p + c; j++) {
				d[j] = e[j];
			}
		}
		printf("%d\n", d[0]);
	}
	return 0;
}

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

using namespace std;

int main(void) {
	int n,r;
	while (cin >> n >> r, n) {
		list<int> hana;
		for (int i = 0; i < n; ++i) {
			hana.push_back(i+1);
		}
		
		int p,c,count;
		for (int i = 0; i < r; ++i) {
			cin >> p >> c;
			count = 1;
			for (list<int>::iterator itr = hana.begin(); itr != hana.end();) {
				if (count > n-(p-1)-c && count < n-(p-2)) {
					hana.push_back(*itr);
					itr = hana.erase(itr);
				}
				else {
					++itr;
				}
				++count;
			}
		}
		count = 1;
		for (list<int>::iterator itr = hana.begin(); itr != hana.end(); ++itr) {
			if (count == n) {
				cout << *itr << endl;
			}
			++count;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
using namespace std;

typedef vector<int> Ivec;

struct Fuda {
	Fuda *next;
	int num;
};

Fuda Start;
Fuda fuda[50];

Fuda* access(int num) {
	Fuda* f = &Start;
	for (int i = 0; num > i; i++) {
		f = f->next;
	}
	return f;
}

int main() {
	int n, r;

	while (scanf("%d %d", &n, &r)) {
		if (n == 0) return 0;
		for (int i = 1; n > i + 1; i++) {
			fuda[i].next = &fuda[i + 1];
			fuda[i].num = n-i;
		}
		fuda[0].next = &fuda[1];
		fuda[0].num = 1;
		fuda[n - 1].num = n;
		Start.next = &fuda[0];

		int p, c;
		for (int i = 0; r > i; i++) {
			scanf("%d %d", &p, &c);
			Fuda* f[5] = { access(p + c - 1), access(1), access(p - 1),access(p + c), access(p) };
			f[0]->next = f[1];
			f[2]->next = f[3];
			Start.next = f[4];
		}
		printf("%d\n", access(1)->num);
	}


	return 0;
}

C++: #include<cstdio>

using namespace std;

int main(){
	for(int n,r;scanf("%d%d",&n,&r),n;){
		int p[50],c[50],i;
		for(i=0;i<r;i++) scanf("%d%d",p+i,c+i);

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

	return 0;
}

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

using namespace std;

int main(){
  int maisu[50];
  int katto;
  int swap[50];
  int p,c;
  int i,j=0;

  for(i=0; i<50; i++){
    maisu[i] = i;
  }

  cout << maisu[0] << endl;

  cin >> katto;
  
  while(j <= katto){
  
    while(true){
      scanf("%d%d",&p,&c);
      if(p == 0 && c == 0){
	break;
      }
      for(i=0; i<c; i++){  
	swap[i] = maisu[i + p-1];
      }
      for(i = 0; i<p-1; i++){
	swap[i+c] = maisu[i];
      }
      for(i=0;i<p+c-1; i++){
	maisu[i] = swap[i];
      }
    }
    if(p == 0 && c == 0){
	break;
    }
  }
    cout << maisu[0] << endl;
 
    return 0;
}