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>

int main(void){
  int n;
  int r;
  int p;
  int c;
  int i;
  int j;
  for(;;){
    scanf("%d %d",&n,&r);
    if(n==0)
      {
	if(r==0){break;}
      }
    int card[n];
    for(i=n;i>0;i--)
      {
	card[n-i]=i;
      }
    /*--------------確認用-------------------
    printf("card:");
    for(i=0;i<n;i++)
      {
	printf("%d ",card[i]);
      }
    printf("\n");
    /*--------------------------------------*/
    for(i=0;i<r;i++)
      {
	scanf("%d %d",&p,&c);
	int card_p[p-1];
	int card_c[c];
	for(j=0;j<p-1;j++)
	  {
	    card_p[j]=card[j];
	  }
	/*---------確認用-------------------------
	printf("card_p:");
	for(j=0;j<p-1;j++)
	  {
	    printf("%d ",card_p[j]);
	  }
	printf("\n");
	/*----------------------------------------*/
	for(j=0;j<c;j++)
	  {
	    card_c[j]=card[p+j-1];
	  }
	/*---------確認用-------------------------
	printf("card_c:");
	for(j=0;j<c;j++)
	  {
	    printf("%d ",card_c[j]);
	  }
	printf("\n");
	/*----------------------------------------*/
	for(j=0;j<c;j++)
	  {
	    card[j]=card_c[j];
	  }
	for(j=0;j<p-1;j++)
	  {
	    card[c+j]=card_p[j];
	  }
	/*-----------------------------------------
	for(j=0;j<n;j++)
	  {
	    printf("%d ",card[j]);
	  }
	printf("\n");
	/*----------------------------------------*/
      }
    printf("%d\n",card[0]);
  }
  
  return 0;
}

C++: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (true) {
        int n,r; cin >> n >> r;
        if (n == 0 && r == 0) break;
        vector<vector<int>> card(r+1, vector<int>(n));
        rep(i,n) card[0][i] = n-i;
        rep(i,r) {
            int p,c; cin >> p >> c;
            rep(j,n) {
                if (j < c) {
                    card[i+1][j] = card[i][j+p-1];
                } else if (c <= j && j < p-1+c) {
                    card[i+1][j] = card[i][j-c];
                } else card[i+1][j] = card[i][j];
            }
        }
        cout << card[r][0] << endl;
    }
}

C++: #include <stdio.h>
#include<stdlib.h>
#define MAX 51
struct node{int x; struct node* next;};

void initcard(struct node *p){
  p = NULL;
  return;
}
struct node* push_card(struct node *p,int n){
  struct node *x;
  x = (struct node*)malloc(sizeof(struct node));
  x->x = n;
  x->next = p;
  p = x;
  return p;
}

struct node* cut(struct node *q,int p,int c){
  struct node *head,*tail,*b;
  int i;
  if(p==1)return q;
  head = q;
  //printf("%d",q->x);
  for(i=1;i<p-1;i++)q = q->next;
  tail = q;//一番下になる
  b = q->next;//一番上になる
  for(i=0;i<c;i++)q=q->next;
  tail->next = q->next;
  q->next = head;
  return b;
}

void c_free(struct node* p){
  struct node *a;
  while(p!=NULL){
    p = p->next;
    a = p;
    free(a);
  }
  return;
}
int main(){
  struct node *card;
  int i,j,n,r,p,c,m[MAX],str[MAX];
  scanf("%d %d",&n,&r);
  while(n){
    card = NULL;
    for(i=1;i<=n;i++)card = push_card(card,i);
    /*while(card!=NULL){
      printf("%d ",card->x);
      card=card->next;
    }
    printf("\n");*/
      for(j=0;j<r;j++){
        scanf("%d %d",&p,&c);
        card = cut(card,p,c);
        /*while(card!=NULL){
          printf("%d ",card->x);
          card=card->next;
        }
        printf("\n");*/
      }
      printf("%d\n",card->x);
      scanf("%d %d",&n,&r);
    }
      return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 52;
int before[MAXN], after[MAXN];

int main()
{
    int n, r, p, c;
    while(cin >> n >> r && (n && r))
    {
        for(int i = n; i > 0;i--) before[n - i] = i;

        REP(r)
        {
            cin >> p >> c;

            rep(j,p) after[c + j] = before[j];
            rep(j,c) after[j] = before[p - 1 + j];
            rep(j,MAXN) before[j] = after[j];
        }
        cout << before[0] << endl;
    }
    return 0;
}

C++: #include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;

/** Problem1129 : Hanafuda Shuffle **/
int main()
{
	int card[50];
	int n, r, p, c;
	
	while (cin >> n >> r, n||r) {
		
		rep(i, n)
		card[i]=n-i;
		
		rep(k, r) {
			int tmp[n];
			cin >> p >> c;
			
			rep(i, p-1) {
				tmp[i] = card[i];
			}
			rep(i, c) {
				card[i] = card[i+p-1];
			}
			rep(i, p) {
				card[i+c] = tmp[i];
			}
		}
		cout << card[0] << endl;
	}
	return 0;
}

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

using namespace std;


int main(){

	while(1){
		int n,r;	
		cin >> n >> r;
		if(n==0&&r==0) break;
		vector<int> huda(n);
		for(int i=0;i<n;i++) huda[i]=n-i;
		
		for(int i=0;i<r;i++){
			int p,c;
			cin >> p >> c;
			p--;c--;
			for(int j=c;j>=0;j--){
				int a = huda[p+c];
				huda.erase(huda.begin()+p+c);
				huda.insert(huda.begin(),a);
			}
		}

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

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
  int n,r;
  while(cin>>n>>r,n!=0||r!=0){
  int A[n];
  rep(i,n){
    A[i]=n-i;
  }
  rep(i,r){
    int p,c;
    cin>>p>>c;
    vector<long long> v(c);
    for(int j=p-1;j<p+c-1;j++){
      v[j-(p-1)]=A[j];
    }
    for(int j=p-2;j>=0;j--){
      A[j+c]=A[j];
    }
    for(int j=0;j<c;j++){
      A[j]=v[j];
    }
  }
  cout<<A[0]<<endl;
  }
 return 0;
}