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 <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cmath>
#include <deque>

using namespace std;

int n=0;//num
int r=0;//round

//just simulate
int main(int args, char *argc[]){
  while(cin>>n>>r){
    if(n==0 && r==0)
      return 0;
    deque<int> cards;
    for(int i=0;i<n;i++)
      cards.push_front(i+1);

    //test
    /*for(int i=0;i<n;i++)
      printf("[%d]:%d ",i,cards[i]);
      puts("");
     */

    int a,b;
    for(int i=0;i<r;i++){
      cin>>a>>b;
      //for(int ix=a-1;ix<=a+b-2;ix++){
      for(int ix=a+b-2;ix>=a-1;ix--){
        int temp=cards[a+b-2];
/*        printf("i:%d ix:%d temp:%d\n",i,ix,temp);*/
        cards.erase(cards.begin()+(a+b-2));
        cards.push_front(temp);
      }
/*      printf("i--%d a:%d b:%d -- ",i,a,b);
      for(int i=0;i<n;i++)
        printf("[%d]:%d ",i,cards[i]);
      puts("");*/
    }

/*    cout<<"last\n";
    for(int i=0;i<n;i++)
      printf("[%d]:%d ",i,cards[i]);
    puts("");*/
    cout<<cards[0]<<endl;

    }
    return 0;
  }

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

void rengeSwap(int b,int e,int* ans){
  int tmp[b];
  b--;
  for(int i=0;i<b;i++){
    tmp[i]=ans[i];
  }
  for(int i=b;i<b+e;i++){
    ans[i-b]=ans[i];
  }
  for(int i=e;i<b+e;i++){
    ans[i]=tmp[i-e];
  }
}

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

    for(int i=0;i<r;i++){
      int b,e;
      cin>>b>>e;
      rengeSwap(b,e,ans);
    }
cout << ans[0] << endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define DEC(i, s) for (int i = (s); i >= 0; i--)

#define SIZE(v) (int)((v).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())

int n, r;
int seq[100][100];

int main() {
  while (cin >> n >> r, n|r) {
    REP(i, n) { seq[0][i] = n - i; }
    REP(i, r) {
      int p, c;
      cin >> p >> c;
      p--;
      int index = 0;
      REP(j, c) {
        seq[i + 1][index++] = seq[i][j + p];
      }
      REP(j, n) {
        if (j >= p && j < p + c) { continue; }
        seq[i + 1][index++] = seq[i][j];
      }
    }
    printf("%d\n", seq[r][0]);
  }
}

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


int card[50];
struct CUT{
  int p;
  int c;
};

CUT cut[51];
int swap_p[50];
int swap_c[50];
int n,r;
void solve(){
  for(int i = 0; i < n; i++){
    card[i] = n - i;
  }

  for(int i = 0; i < r ; i++){
    for(int x = 0; x < n; x++){
      cout << card[x] << " ";
    }
    cout << endl;
    for(int j = 0; j < cut[i].p; j++) swap_p[j] = card[j];
    for(int k = 0; k < cut[i].c; k++) swap_c[k] = card[cut[i].p + k - 1];
    for(int l = 0; l < cut[i].p + cut[i].c - 1;l++){
      if(cut[i].c > l)  card[l] = swap_c[l] ;
      else              card[l] = swap_p[ l - cut[i].c ];
    }
  }
  cout << card[0] << endl;
  return ;
}



int main(){
  while(true){
    cin >> n >> r;
    if(n == 0 && r == 0) break;
    for(int input = 0; input < r; input++){
      cin >> cut[input].p >> cut[input].c ;
    }
    solve();
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int d[51];
int cop[51];
int main(void){
  int n,r;
  while(cin>>n>>r){
    if(n==0) break;
    REP(i,n) d[i] = n-i;
    REP(i,r){
      int p,c;
      cin>>p>>c;
      REP(j,c)cop[j] = d[p-1+j];
      for(int j=p-2; j>=0; j--){
        d[j+c] = d[j];
      }
      REP(j,c) d[j] = cop[j];
    }
    cout<<d[0]<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
    int n,r;
    while(scanf("%d %d",&n,&r),n!=0) {
        vector<int> v;
        for(int i=n;i>=1;i--) v.push_back(i);
        for(int i=0;i<r;i++) {
            vector<int> nv;
            int p,c;
            scanf("%d %d",&p,&c);p--;
            for(int i=0;i<c;i++) {
                nv.push_back(v[p+i]);
            }
            for(int i=0;i<p;i++) nv.push_back(v[i]);
            for(int i=p+c;i<n;i++) nv.push_back(v[i]);
            v=nv;
        }
        printf("%d\n",v[0]);
    }
}

C++: #include <bits/stdc++.h>
const long long INF = LLONG_MAX/2;
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ll long long int
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

using namespace std;
ll ans = 0;

ll n, r, a, b;
vector<ll> v, w;

int main()
{
	while (true){
		cin >> n >> r;
		if (!n&&!r) return 0;
		w.resize(n);
		v.resize(n);
		FOR(i, 1, n + 1) v[i - 1] = n - i + 1;
		REP(i, r)
		{
			cin >> a >> b;
			REP(j, b)
			{
				w[j] = v[j + a - 1];
			}
			REP(j, a - 1)
			{
				w[j + b] = v[j];
			}
			FOR(j, a + b - 1, n)
			{
				w[j] = v[j];
			}
			v.clear();
			copy(w.begin(), w.end(), back_inserter(v));
		}
		cout << v[0] << endl;
	}
}

C++: #include <iostream>

using namespace std;

int main()
{
    int n, r;

    while (cin >> n >> r, n || r) {
        int card[51], tmp[51];

        for (int i = 1; i <= 50; i++) 
            card[i] = i;


        for (int i = 0; i < r; i++) {
            int p, c;
            
            cin >> p >> c;
            for (int j = 0; j < c; j++) 
                tmp[j] = card[n - p - c + 2 + j];

            for (int j = 0; j < p - 1; j++) 
                card[n - p - c + 2 + j] = card[n - p + 2 + j];
            for (int j = 0; j < c; j++)
                card[n - c + 1 + j] = tmp[j];
        }
        
        cout << card[n] << endl;
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int n,r, p,c;
  string pile, buf, next;
  while(cin>>n>>r&&(n||r)){
    pile=" ";
    for( int i=n;i>0;i-- )
      pile = pile + (char)i;
    while(r--){
      cin>>p>>c;

      next = " " + pile.substr(p,c);
      if( p != 1)
	next += pile.substr(1, p-1);
      if( c != (int)pile.length() )
	next += pile.substr(p+c);

      pile = next;
    }
    cout << (int)pile[1] << endl;
  }
  return 0;
}

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

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