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 <iostream>

using namespace std;
int main(){
	int zero;
	while(1){
		int card,cut;
		
		cin >> card >> cut;
		if(card == 0 && cut == 0){
			return 0;
		}
		
		int topcard = card;
		
		int *c = new int[cut];
		int *p = new int[cut];

		for(int i=0; i<cut; ++i){
			cin >> p[i] >> c[i];
		}

		for(int i=cut-1; i>=0; --i){
			if(topcard > card-c[i]){
				topcard -= (p[i]-1);
			}
			else if( topcard > card-c[i]-(p[i]-1) ){
				topcard += c[i];
			}
		}
		cout << topcard << endl;
		
		delete[] c;
		delete[] p;
		
	}


}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int n, r;
    cin >> n >> r;
    if (n == 0 && r == 0){
      break;
    }
    vector<int> ans(n);
    for (int i = 0; i < n; i++){
      ans[i] = n - i;
    }
    for (int i = 0; i < r; i++){
      int p, c;
      cin >> p >> c;
      p--;
      vector<int> ans2 = ans;
      for (int j = 0; j < c; j++){
        ans2[j] = ans[j + p];
      }
      for (int j = c; j < c + p; j++){
        ans2[j] = ans[j - c];
      }
      swap(ans, ans2);
    }
    cout << ans[0] << endl;
  }
}

C++: #include <iostream>
#include <map>
#include <string>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n,r;
    while(cin >> n >> r && n){
        string s(n,0);
        rep(i,n) s[n-i-1] = i+1;
        rep(i,r){
            int p,c;
            cin >> p >> c;
            s = s.substr(p-1,c) + s.substr(0,p-1) + s.substr(p-1+c);
        }
        cout << (int)s[0] << endl;
    }
}

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

using namespace std;

int main(){
	vector<int> cards;
	vector<int> ::iterator cardsIterator;
	vector<int> ::iterator shuffuleIterator;
	int n,r,p,c;

	while(cin >> n >> r, n && r){
		cards.clear(); //初期化
		// カードの山生成
		for (int i = 0; i < n; ++i){
			cards.push_back(i+1);
		}
		// シャッフル
		while(cin >> p >> c, r--){
			cardsIterator = cards.end();
			cardsIterator -= p + (c - 1);
			while(c--){
				cards.push_back(*cardsIterator);
				cards.erase(cardsIterator);
			}
			// if (r == 0){
			// 	break;
			// }
		}
		// 一番上のカード表示
		cout << cards.back() << endl;
	}
}

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

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

C++: #include<cstdio>
void shuffle (int [], int, int);

int main(){
  int n,r,p,c;
  while(1){
    scanf("%d%d",&n,&r);
    if(n==0 && r==0)
      break;
    int data[n];
    for(int i=0;i<n;i++)
      data[i]=n-i;
    for(int i=0;i<r;i++){
      scanf("%d%d",&p,&c);
      shuffle(data,p,c);
    }
    printf("%d\n",data[0]);
  }
  return 0;
  
}

void shuffle(int data[] ,  int p ,int c){
  int bd[c];
  p--;
  for(int i=0;i<c;i++)
    bd[i]=data[p+i];
  for(int i=0;i<p;i++)
    data[p+c-1-i]=data[p-1-i];
  for(int i=0;i<c;i++)
    data[i]=bd[i];
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
const int INF = 1e9;
const int MOD = 1000000007;

int main(){
    while(1){
        int n,r;
        cin >> n >> r;
        if(n==0 && r==0) break;
        vector<int> a(n);
        iota(a.rbegin(),a.rend(),1);
        rep(i,r){
            int p,c;
            cin >> p >> c;
            rotate(a.begin(),a.begin()+p-1,a.begin()+p-1+c);
        }
        cout << a[0] << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#define N 50
using namespace std;

int main(){

  int n,r,ans;
  int operate[N][2];

  while(true)
    {
      cin >> n >> r;
      if(n == 0 && r == 0)break;

      for(int i=0;i<r;i++)cin >> operate[i][0] >> operate[i][1];
      ans = n;

     
      for(int i=r-1;i>=0;i--){
	if(n-operate[i][1] <= ans && ans <= n)
	  {
	    if(n == operate[i][1])continue;
	    ans = ans-operate[i][0]+1;
	   
	    continue;
	  }
	else{
	  ans += operate[i][1];


	}
      }

      cout << ans << endl;



    }

}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
	int card[50][50]={0};
	int mem[50]={0};
	int n;
	int r;
	int k = 0 ;
	int p,c;
	while(1){
		cin >>n >>r;
		if ((n==0)&&(r==0)) break;
		for(int i =0;i<n;i++){
			card[k][i]=i;
		}	
		for (int j=0;j<r;j++){
			cin >> p >> c ;
			for(int l=0;l<n;l++){
				mem[l]=card[k][l];
			}
			for(int m=0;m<p-1;m++){
				card[k][n-p-c+1+m]=mem[n-p+1+m];
			}
			for(int l=0;l<c;l++){
				card[k][n-c+l]=mem[n-p-c+1+l];
			}
		}
		cout << card[k][n-1] <<endl;
		k++;

	}
	
	return 0;
}

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

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

int card[51];
int ncard[51];
int n, r, c, p;

int main()
{
    while(cin >> n >> r && n)
    {
        REP(n) card[i] = n - i;

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

            rep(j,n) ncard[j] = card[j];
            //rep(j,n)cout <<j<< ":" << card[j] << endl;
            
            rep(j,p - 1) ncard[c + j] = card[j];
            rep(j, c) ncard[j] = card[j + p - 1];
            
            rep(j,n) card[j] = ncard[j];
        }
       // REP(n)cout <<i << ":" << card[i] << endl;

        cout << card[0] << endl;

    }
    
    return 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;
}