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>

using namespace std;

int data[50], n, r, p, c, tmp[50], next[50];

main(){
  while(cin >> n >> r && (n|r)){
    for(int i=0;i<n;i++) data[i] = n-i;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      for(int j=0;j<p-1;j++) tmp[j] = data[j];
      for(int j=0;j<c;j++) next[j] = data[p-1+j];
      for(int j=0;j<p-1;j++) next[c+j] = tmp[j];
      for(int j=0;j<p+c;j++) data[j] = next[j];
    }
    cout << data[0] << endl;
  }
}

C++: #include <cstdio>

using namespace std;

int n, r;
// greater is upper
int D[51];
int X[51];

int main() {
    for (;;) {
        scanf("%d%d", &n, &r);
        if (!n && !r) { break; }

        for (int i = 1; i <= 50; i++) {
            D[i] = i;
        }

        for (int i = 0; i < r; i++) {
            int p, c;
            scanf("%d%d", &p, &c);
            for (int j = 0; j < c; j++) {
                X[j] = D[n - (p - 1) - c + 1 + j];
            }
            for (int j = 0; j < p - 1; j++) {
                D[n - (p - 1) - c + 1 + j] = D[n - (p - 1) - c + 1 + j + c];
            }
            for (int j = 0; j < c; j++) {
                D[n - c + 1 + j] = X[j];
            }
        }

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

C++: #include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X)  ( (X)*(X) )
#define CUBE(X) ( (X)*(X)*(X) )
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;
 
 
void reader(int &a){scanf("%d",&a);}
void reader(double &a){scanf("%lf",&a);}
void reader(char a[]){scanf("%s",a);}
void reader(ll &a){scanf("%lld",&a);}
void reader(ull &a){scanf("%llu",&a);}
// void reader(string& a){cin >> a;};
template<class T,class U> void reader(T& t,U& u){reader(t); reader(u);}
template<class T,class U,class V> void reader(T& t,U& u,V& v){reader(t); reader(u); reader(v);}
 
void writer(int a,char c) {printf("%d",a); putchar(c);}
void writer(ll a,char c) {printf("%lld",a); putchar(c);}
void writer(double a,char c) {printf("%.20lf",a); putchar(c);}
void writer(char a[]) {printf("%s",a);};
void writer(char a[],char c) {printf("%s",a);putchar(c);};
void writer(char a,char c) {putchar(a); putchar(c);};
template<class T>void writerLn(T t){writer(t,'\n');}
template<class T,class U>void writerLn(T t,U u){writer(t,' ');writer(u,'\n');}
template<class T,class U,class V> void writerLn(T t,U u,V v){writer(t,' ');writer(u,' ');writer(v,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){putchar('\n');return;}rep(i,n-1) writer(x[i],' ');writer(x[n-1],'\n');}
template<class T> void writerVec(vector<T> x){int n=x.size();int i;if(!n){putchar('\n');return;}rep(i,n-1) writer(x[i],' ');writer(x[n-1],'\n');}
 

 
// #define int ll
 
bool test = 1;

//............................
#define MAX 300000
signed main(){
  int i,j,k,l;
  while(1) {
	int n,r;
	cin >> n >> r;
	if(n == 0) break;
	vector<int> now(n);
	rep(i,n) {
	  now[i] = n-1-i;
	}
	rep(i,r) {
	  int p,c;
	  cin >> p >> c;
	  vector<int> next = now;
	  rep(j,c) {
		next[j] = now[p-1+j];
	  }
	  rep(j,p-1) {
		next[c+j] = now[j];
	  }
	  now = next;
	}
	cout << now[0]+1 << endl;
  }
  return 0;
}

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

using namespace std;

void sort(int *x, int *y)
{
	int temp;
	temp = *x;
	*x = *y;
	*y = temp;
}

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

		int p, c;

		for(int i = 0; i < r; i++)
		{
			cin >> p >> c;
			vector<int> B(p);
			
			int j = 0;
			for(int i = 0; i < p-1;i++)
				B[i] = A[i];

			for(int i = p-1; i < p+c-1; i++)
				sort(&A[i], &A[i-(p-1)]);

			for(int i = c; i < c+p-1;i++)
				A[i] = B[i-c];
		}
		cout << A[0] << endl;
	}
	return 0;
}

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

int main() {
  // 変数の準備。デッキの余分な50枚はカードを一時的に移して置くための場所
  int deck[100] = {}, num, times, p, c;

  while (cin >> num >> times && num) {  // デッキが0枚だったら終了

    // デッキの準備
    for (int i = 0; i < num; i++) {
      deck[i] = num - i;
    }

    // デッキにシャッフルの操作をtimes回する
    for (int i = 0; i < times; i++) {
      cin >> p >> c;

      // 先頭p-1枚を一時的に退避
      for (int j = 0; j < p - 1; j++) {
        deck[j + 50] = deck[j];
      }

      // 図の黄色の矢印の操作
      for (int j = 0; j < c; j++) {
        deck[j] = deck[j + p - 1];
      }

      // 退避させてたカードを戻す。図の青色の操作。
      for (int j = 0; j < p - 1; j++) {
        deck[c + j] = deck[j + 50];
      }
    }

    // デッキの一番上のカードを出力
    cout << deck[0] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <functional>

using namespace std;

int INF = 10000000;

int n , r;
int N[50];


int main()
{

	while(cin >> n >> r && n && r)
	{
		for(int i = 0;i < n;i++)N[i] = n-i-1;

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

			int temp;
			int t = 0;

			for(int j = p;j < p+c;j++)
			{
				temp = N[j];
				for(int k = 0;j-c-k >= 0;k++)
				{
					N[j-k] = N[j-c-k];
				}
				N[t] = temp;
				t++;
			}

		}

		cout << N[0]+1 << endl;



	}

  return 0;
}