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 <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

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

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

using namespace std;

int top_search(int,int,int,int *);
int main(){
	int n,r,c,p;
	int cnt=0;
	int top[51];
	while(1){
		cin>>n>>r;
		if(n==0&&r==0)
			break;
		int *hanahuda=new int[n+1];

		for (int i = n-1; i>=0 ; i--)
			hanahuda[i]=n-i;

		for(int i=0;i<r;i++){
			cin>>p>>c;
			top[cnt]=top_search(n,p,c,hanahuda);
		}
		delete[] hanahuda;
		cnt++;
	}
	for(int m=0;m<cnt;m++)
		cout<<top[m]<<endl;
	return 0;
}
int top_search(int n,int p,int c,int *hanahuda){
	int cnt=0;
	for(int k=p-1;k<p+c-1;k++){

		int nokori=hanahuda[k];

		for(int l=p-2;l>=0;l--)
			hanahuda[l+1]=hanahuda[l];


		hanahuda[cnt]=nokori;
		cnt++;
	}

	return *hanahuda;
}

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[100];
  int r[100];
  int p[100][200];
  int c[100][200];
  int c_tmp[100][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>
#include<cstdio>
#include<list>
#include<vector>
using namespace std;

int main() {
	int a, b;
	while (cin >> a >> b, a | b) {
		list<int>L;
		for (int c = 0; c < a; c++)L.push_back(a-c);
		for (int d = 0; d < b; d++) {
			int e, f, i = 1;
			scanf("%d%d", &e, &f);
			vector<int>V;
			for (auto g = L.begin(); g != L.end(); g++,i++) {
				if (i >= e&&e + f > i) {
					V.push_back(*g);
					L.erase(g);
					g--;
				}
			}
			for (int r = 0; r < V.size(); r++)L.push_front(V[V.size() - r - 1]);
		}
		cout << L.front() << endl;
	}
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n, r;
        cin >> n >> r;
        if(n == 0)
            break;
        vector<int> p(r), c(r);
        for(int i=0; i<r; ++i)
            cin >> p[i] >> c[i];

        int ret = 1;
        for(int i=r-1; i>=0; --i){
            if(ret <= c[i])
                ret += p[i] - 1;
            else if(ret <= c[i] + p[i] - 1)
                ret -= c[i];
        }
        cout << (n - ret + 1) << 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<c;l++){
				mem[l]=card[k][n-p-c+1+l];
			}
			for(int m=0;m<p-1;m++){
				card[k][n-p-c+1+m]=card[k][n-p+1+m];
			}
			for(int l=0;l<c;l++){
				card[k][n-c+l-1]=mem[l];
			}
		}
		cout << card[k][n-1] <<endl;
		k++;

	}
	
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int input(char s[]);

int main() {
	int n, r,brk=0,p,c,x[50],xs[50];
	for (int i = 0; i < 50; i++)
		x[i] = xs[i] = i;

	while (1) {
		scanf("%d", &n);
		scanf(" %d", &r);
		if (n == 0 && r == 0)
			brk = 1;
		for (int i = 0; i < r&&brk == 0; i++) {
			scanf("%d %d", &p, &c);
			for (int j = 0; j < c; j++)
				x[j] = xs[j + p - 1];
			for (int j = c; j < c + p - 1; j++)
				x[j] = xs[j - c];
			for (int j = 0; j < n; j++)
				xs[j] = x[j];}
		if (brk == 1)
			break;
		else 
			printf("%d", n-x[0]);
	}
	return 0;
}

C++: #include <cstdio>

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

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

#define pb         push_back

const int INF = 100000000;

int main(void) {
	while(1){
		int n, r;
		vector<int> card;
		cin >> n >> r;
		if(n == 0 && r == 0) break;

		for(int i=n; i>=1; i--){
			card.pb(i);
		}
		for(int i=0; i<r; i++){
			int p, c;
			cin >> p >> c;
			vector<int> tmp;

			for(int i=p-1; i< p-1+c; i++){
				tmp.pb(card[i]);
			}
			for(int i=0; i < p-1; i++){
				tmp.pb(card[i]);
			}
			for(int i=p-1+c; i < card.size(); i++){
				tmp.pb(card[i]);
			}

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

C++: #include<iostream>
#include<string>
using namespace std;
main(){
 for(int n,r,p,c;cin>>n>>r;){
  if(!n&&!r)break;
  string d;
  for(int i=0;i<n;i++)d=char(48+i)+d;
  for(int i=0;i<r;i++){cin>>p>>c;
   d = d.substr(p-1,c)+d.substr(0,p-1)+d.substr(p+c-1);}
  cout<<(d[0]-47)<<endl;
 }
}