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 <vector>
#include <algorithm>

using namespace std;

int main(void)
{
	int n, r;
	while(cin >> n >> r, n > 0){
		vector<int> card(n);
		//カード番号初期化
		for(int i=0;i<n;i++){
			card[i] = n-i;
		}
		//シャッフル処理
		for(int i=0;i<r;i++){
			int p, c;
			cin >> p >> c;
			rotate(card.begin(), card.begin()+p-1, card.begin()+p+c-1);
		}
		cout << card[0] << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,r,i,p,c,v;
  int array[100];
  int box[100];
  while(1){
    cin>>n>>r;
   
    if(n==0&&r==0) break;
    else{
      for(i=0;i<n;i++){
	box[i]=i+1;
      }
     
      for(i=0;i<r;i++){
	v=i;
	cin>>p>>c;
	for(i=0;i<c;i++){
	  array[i]=box[n-p-i];
	 
	}
	for(i=0;i<p-1;i++){
	 box[n-p-c+1+i]=box[n-p+1+i];
	  
	}
	for(i=0;i<c;i++){
	  box[n-1-i]=array[i];
	  
	}
	i=v;
      }
	cout<<box[n-1]<<endl;

    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;

int main(void) {
	int N, R;
	while (cin >> N >> R, N) {
		if (N == 1){
			cout << 1 << endl;
			continue;
		}
		
		stack<int> yama;
		for (int i = 1; i <= N; i++) {
			yama.push(i);
		}

		for (int i = 0; i < R; i++) {
			stack<int> p;
			stack<int> c;
			int begin, size;
			cin >> begin >> size;

			for (int j = 0; j < begin - 1; j++) {
				p.push( yama.top() );
				yama.pop();
			}
			for (int j = 0; j < size; j++) {
				c.push ( yama.top() );
				yama.pop();
			}

			while (!p.empty()) {
				yama.push( p.top() );
				p.pop();
			}
			while (!c.empty()) {
				yama.push( c.top() );
				c.pop();
			}
		}

		cout << yama.top() << endl << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
const ll mod = 1e9 + 7;

int main() {
	cin.sync_with_stdio(false);
	int n,r;
	vector<int>ans;
	while (1) {
		cin >> n >> r;
		if (n == 0 && r == 0)break;
		vector<int>b(n), a(n);
		int p, c;
		rep(i, n)b[i] = n-i;
		rep(i, r) {
			cin >> p >> c;
			rep(j, c)a[j] = b[p - 1 + j];
			rep(j, p-1)a[c + j] = b[j];
			reps(j, p + c - 1, n)a[j] = b[j];
			rep(j, n)b[j] = a[j];			
		}
		ans.push_back(a[0]);

	}
	for (auto x : ans)cout << x << endl;
	return 0;
}

C++: #include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
struct ml{
  int dt;
  struct ml *nx;
};
typedef struct ml Ml;
void f(Ml *a,int p,int q){
  int i;
  Ml *b,*c,*d;
  b=a;
  for(i=0;i<p-1;i++)
    b=b->nx;
  c=b;
  for(i=0;i<q;i++)
    c=c->nx;
  d=a->nx;
  a->nx=b->nx;
  b->nx=c->nx;
  c->nx=d;
  return;
}
int main(){
  int i;
  int n,r,p,q;
  Ml *a;
  while(cin>>n>>r&&n+r){
    a=(Ml*)malloc((n+2)*sizeof(Ml));
    for(i=0;i<n+1;i++){
      (a+i)->dt=n-i+1;
      (a+i)->nx=a+i+1;
    }
    (a+i)->dt=n-i+1;
    for(i=0;i<r;i++){
      cin>>p>>q;
      if(p!=1)
	f(a,p,q);
    }
    cout<<a->nx->dt<<endl;
    free(a);
  }
  return 0;
}

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

int n,r;

int main(){

	while(1){
    cin >> n >> r;
    if ((n == 0)&&(r == 0)){
          break;
		}
	int A[n];
for (int i = 0; i <= n-1; i++){
		A[i] = n-i;
		//cout << A[i] << endl;
	}
	int p,c;


for (int i = r; i >=1; i--){

		cin >> p >> c;

		int M[p-1];
		int N[c];
for (int i = 0; i <= p-2; i++){
			M[i] = A[i];
		}
for (int i = 0; i <= c-1; i++){
			N[i] = A[p-1+i];
		}
		//??????
for (int i = 0; i <= c-1; i++){
			A[i]  = N[i];
		}
for (int i = 0; i <= p-2; i++){
			A[c+i]  = M[i];
		}
		if(i == 1){
			cout << A[0] << endl;
		}

	}
  }
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

bool debug=false;
/*---------------------------------------------------*/

int n,r,p,c;
int card[55];

void init(int n){
  rep(i,n)card[i]=n-i;
}

void shuffle(){
  int tmp[55];
  rep(i,r){
    cin>>p>>c;
    rep(i,c)tmp[i]=card[p+i-1];
    if(debug){cout<<"tmp ";rep(i,c)cout<<tmp[i]<<" ";cout<<endl;}
    for(int i=p-2;i>=0;i--)card[i+c]=card[i];
    rep(i,c)card[i]=tmp[i];
    if(debug){rep(i,n)cout<<card[i]<<" ";cout<<endl;}
  }
}

int main(){

  while(cin>>n>>r){
    if(n==0&&r==0)break;
    init(n);
    shuffle();
    cout<<card[0]<<endl;
  }
  
  return 0;
}

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

int main(){
	
	int n,r;
	while(cin>>n>>r){
		if(n!=r!=0){
		int h[55]={0},m[55]={0};
		int p,d;
		for(int i=0;i<n;i++)
			h[i]=n-i;
		while(r>0){
			cin>>p>>d;
			int j=d-1;
			for(int i=p+d-1;i>=p;i--)
				m[j--]=h[i-1];
			for(int i=p-1;i>0;i--)
				h[i+d-1]=h[i-1];
			for(int i=d;i>0;i--)
				h[i-1]=m[i-1];
			r--;
	}
			cout<<h[0]<<endl;
	}
	else
		break;
	}
	
}

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

#define MAX_N 100

using namespace std;

int main(int argc, char const *argv[])
{
	int n,r;
	int p,c;
	int h[MAX_N];

	while(1){

		cin>>n>>r;
		if (n+r==0){
			break;
		}

		for(int i1=0;i1<n;i1++){
			h[i1]=n-i1;
		}

		for(int i1=0;i1<r;i1++){
			cin>>p>>c;
			queue<int> q1;
			queue<int> q2;

			for(int i2=0;i2<p-1;i2++){
				q1.push(h[i2]);
			}
			for(int i2=0;i2<c;i2++){
				q2.push(h[i2+p-1]);
			}
			for(int i2=0;i2<p-1+c;i2++){
				if(i2<c) {
					h[i2]=q2.front();
					q2.pop();
				}
				else {
					h[i2]=q1.front();
					q1.pop();
				}
			}
		}
		cout<<h[0]<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int main(void){
while(1){
int n,r;
cin>>n>>r;
if(n==0)break;
vector<int> a(n);
for(int i=0;i<n;i++)a[i]=n-i;
for(int i=0;i<r;i++){
int p,c;
cin>>p>>c;
vector<int> temp(p+c-1);
for(int j=0;j<c;j++)temp[j]=a[p+j-1];
for(int j=c;j<c+p-1;j++)temp[j]=a[j-c];
for(int j=0;j<c+p-1;j++)a[j]=temp[j];
//for(int j=0;j<n;j++)cout<<a[j]<<endl;
	}	
cout<<a[0]<<endl;
}
return 0;
}