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 <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[51];

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 = n;
		fuda[n - 1].num = 1;
		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<iostream>
#include<vector>
using namespace std;

int main(){
  int n,r,c,p;
  vector<int> num(50),ans(50);
  
  while(1){
    cin>>n>>r;
    if(n==0&&r==0)break;
    for(int i=0;i<n;i++) num[n-i-1]=ans[n-i-1]=i+1;
   
    for(int i=0;i<r;i++){
      cin>>c>>p;
      for(int j=0;j<p;j++){      
	int l=0;
	ans[0]=num[c-1];
	for(int k=1;k<n;k++){
	  if(k!=c)ans[k]=num[l];
	  else ans[k]=num[++l];
	  l++;
	}
	for(int k=0;k<n;k++)num[k]=ans[k];
	if(c>=p)for(int m=0;m<p;m++)ans[p-1-m]=num[m];
      }
      //  for(int i=0;i<n;i++)cout<<ans[i]<<endl;
    }
    cout<<ans[0]<<endl;
  }
  
  return 0;
}

C++: 
#include<cstdio>
#include<iostream>
#include<string>
#include <algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<set>
using namespace std;
using ll = long long;

int n, r, a, b;
int t[100];
int u[100], size;
int main() {
	while (cin >> n >> r && n&&r) {
		for (int i = 0; i<n; i++)t[i] = n - i;
		for (int i = 0; i<r; i++) {
			cin >> a >> b;
			for (int j = 0; j<b; j++)u[j] = t[j + a - 1];
			for (int j = a - 2; j >= 0; j--)t[j + b] = t[j];
			for (int j = 0; j<b; j++)t[j] = u[j];
		}
		cout << t[0] << endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
  
int main()
{
	int n,m;
	int p[51]={0};
	int c[51]={0};
	int i;
	int ans;

	while(1)
	{
	scanf("%d %d",&n,&m);
	if((n==0)&&(m==0))
		break;
	ans=n;

	for(i=1;i<=m;i++){
		scanf("%d %d",&p[i],&c[i]);	
	} 

	for(i=m;i>=1;i--){
		if(p[i]!=1){
		if((n-p[i]+1-c[i])>ans){
		}else if(ans>(n-c[i])){
			ans = ans-p[i]+1;
		}else
			ans = ans+c[i];
		}
	}
	printf("%d\n",ans);

	}
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
#include<string.h>
using namespace std;

typedef long long int64;
typedef int int32;
typedef char int8;

#define rep(i,j) for(int i=0;i<j;i++)
#define repeat(i,j,k) for(int i=(j),i<(k);i++)
#define repeat_eq(i,j,k) for(int i=(j),i<=(k);i++)
#define rev_rep(i,j,k) for(int i=(j)-1;i>=k;i--)
#define all(v) (v).begin(),(v).end()

const int INF=1<<30;//=10E10

void mycopy(int *out,int *in,int num){
  copy(in,in+num,out);
}

int main()
{
  while(true){
    int n,r;cin>>n>>r;
    if(!n && !r)break;
    int card[2][51];
    rep(i,n)card[0][i]=n-i;//初期化
    rep(i,r){
      int p,c;cin>>p>>c;
      
      mycopy(card[1],card[0]+p-1,c);
      mycopy(card[1]+c,card[0],p-1);
      mycopy(card[0],card[1],p+c-1);
      
    }
    cout<<card[0][0]<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e17;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)




int main() {
    int n, r;
    cin >> n >> r;
    
    while(n != 0 || r != 0){
        vector<int> k(n);
        REP(i, n){
            k[i] = n - i;
        }
        
        REP(i, r){
            int p, c;
            cin >> p >> c;
            vector<int> t(c);
            REP(j, c){
                t[j] = k[p - 1 + j];
            }
            for(int j = p + c - 2; j >= c; j--){
                k[j] = k[j - c];
            }
            REP(j, c){
                k[j] = t[j];
            }
        }
        
        cout << k[0] << endl;
        
        cin >> n >> r;
    }
}

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

#define loop(i) for(int lp = 0; (lp) < (i); (lp) ++)

using namespace std;

int main() {
  int n, r, p, c;
  vector<int> card;
  
  while(cin >> n >> r, n) {
    card.clear();
    for(int i = n; i > 0; i --) {
      card.push_back(i);
    }
    
    for(int i = 0; i < r; i ++) {
      cin >> p >> c;

      loop(c) {
	for(int j = (p-1)+(c-1); j > 0; j --) {
	  swap(card[j], card[j-1]);
	}
      }
    }

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

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


int main(){
	while (true){
		int n, r,a[50];
		cin >> n >> r;
		if (n == 0 && r == 0){ break; }
		for (int i = 0; i < 50; i++){
			a[i] = i;
		}

		for (int i = 0; i < r; i++){
			int p, c, b[50];
			cin >> p >> c;
			for (int j = 0; j < p; j++){
				b[j] = a[j];
			}
			for (int j = 0; j < c; j++){
				a[j] = a[p + j];
			}
			for (int j = 0; j < p; j++){
				a[c + j] = b[j];
			}
		}

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

C++: #include <stdio.h>

int main(void){
  int n, r, p, c;
  while(1){
    scanf("%d%d", &n, &r);
    if (n==0 && r==0){
      break;
    }
    int card[n], temp[n];
    for(int i=0;i<n;i++){
      card[i] = n-i;
    }
    for(i=0;i<r;i++){
      scanf("%d%d", &p, &c);
      //カットの処理
      for(i=p-1;i<p+c-1;i++){
        temp[i-p+1] = card[i];
      }
      for(i=0;i<p-1;i++){
        card[p+c-2-i] = card[p-2-i];
      }
      for(i=0;i<c;i++){
        card[i] = temp[i];
      }
    }
    printf("%d", card[0]);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};



int main(){
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0) break;
		vi a(n);
		for(int i=0;i<n;i++) a[i]=n-i;
		for(int i=0;i<m;i++){
			int x,y;
			cin>>x>>y;
			vi b;
			x--;
			for(int i=0;i<y;i++) b.push_back(a[x+i]);
			for(int i=0;i<x;i++) b.push_back(a[i]);
			for(int i=x+y;i<n;i++) b.push_back(a[i]);
			a=b;
		}
		cout<<a[0]<<endl;
	}
}