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<bits/stdc++.h>
using namespace std;

int main(){
	int n, r, p, c, temp[200], tempp[200] = {}, tempc[200] = {}, i;
	
	while(1){
		cin>>n>>r;
		
		if(n == 0 && r == 0) break;
		
		for(i = 1; i <= n; i++) temp[i] = n-i+1;
		//for(i = 1; i < n; i++) cout<<temp[i]<<endl;
		for(int j = 0; j < r; j++){
			cin>>p>>c;
			for(i = 1; i < p; i++) tempp[i] = temp[i];
			for(i = 1; i <= c; i++) tempc[i] = temp[i+p-1];
			for(i = 1; i <= c; i++) temp[i] = tempc[i];
			for(i = 1; i < p; i++) temp[i+c] = tempp[i];
		}
	//	for(i = 1; i < n; i++) cout<<temp[i]<<" "<<tempc[i]<<" "<<tempp[i]<<endl;
		cout<<temp[1]<<endl;
		
	}
	
	
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int n, r, p, c;
	int i,j;
	while (cin >> n >> r) {
		if (n == 0 && r == 0)break;
		int sta[50]; int copsta[50];
		for (i = 0; i < n; i++) {
			sta[i] = n-i;
		}
		for (i = 0; i < r; i++) {
			for (j = 0; j < n; j++) {
				copsta[j] = sta[j];
			}
			cin >> p >> c;
			for (j = 0; j < p + c - 1; j++) {
				if (j < c) {
					sta[j] = copsta[j + p-1];
				}
				else sta[j] = copsta[j - c];
			}
		}
		cout << sta[0] << endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

const int MAX = 50;

int data[MAX];
int in,num;
int copyA[MAX];

void change(int p, int c){

  for(int i = p; i < p+c; i++) data[i-p] = copyA[i];
  for(int i = 0; i < p; i++) data[i+c] = copyA[i]; 
}
void make(){
  for(int i = 0; i < in; i++) data[i] = i;
}
void copy_1(){
  for(int i = 0; i < in; i++) copyA[i] = data[i];
}

int main(){

  while(cin >> in >> num && in+num){
    make();
    for(int i = 0; i < num; i++){
      int p,c;
      cin >> p >> c;
      copy_1();
      change(p-1,c);
    }
    cout << in - data[0] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
using namespace std;

typedef vector<int> Ivec;

int main() {
	int n, r;

	while (scanf("%d %d", &n, &r)) {
		if (n == 0) 
			return 0;

		Ivec fuda;
		for (int i = n; 0 < i; i--)
			fuda.push_back(i);

		int p, c;
		for (int i = 0; r > i; i++) {
			scanf("%d %d", &p, &c);
			Ivec buf(fuda);
			for (int j = 0; c > j; j++) {
				fuda.erase(fuda.begin()+p-1+j);
				fuda.insert(fuda.begin()+j, buf[p-1+j]);
			}
		}
		printf("%d\n", fuda[0]);
	}
	return 0;
}

C++: #include<string>
#include<vector>
#include<iostream>
 
using namespace std;
 
int main()
{
    int n, r;
    while(cin >> n >> r){
        if(n==0 && r==0) break;
        vector<int> huda;
        for(int i=0;i<n;i++){
            huda.push_back(n-i);
        }
        /*
		for(int i=0;i<n;i++){
            cout<<huda[i]<<endl;
        }
        cout<<endl;
		*/
        for(int i=0;i<r;i++){
            int p, c;
            cin >> p >> c;
            vector<int> temp;
            for(int j=0;j<c;j++){
				temp.push_back(huda[p-1+j]);
            }
            /*
			cout<<"temp"<<endl;
            for(int i=0;i<temp.size();i++){
                cout<<temp[i]<<endl;
            }
            cout<<endl;
            */
            for(int j=c-1;(p-1+j-c)>=0;j--){
				//cout << p-1+j << " " << p-1+j-c <<endl;
				huda[p-1+j]=huda[p-1+j-c];
			}
            //cout <<endl;
            for(int j=0;j<c;j++){
                huda[j]=temp[j];
            }
            /*
			for(int i=0;i<n;i++){
				cout<<huda[i]<<endl;
			}
	        cout <<endl;
			*/
        }
        /*
        for(int i=0;i<n;i++){
            cout<<huda[i]<<endl;
        }
        cout <<endl;
        */
        cout << huda[0] << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<list>
using namespace std;
bool b[33000];
int main() {	
	int n, m;
	while (cin >> n >> m&&n != 0) {
		list<int>a;
		list<int>::iterator it;
		list<int>::iterator it2;
		for (int i = 1; i <= n; i++) a.push_back(i);
		for (int z = 0; z < m; z++) {		
			list<int>b;
			int p, s;
			cin >> p >> s;
			for (int i = 0; i < p; i++)it++;
			it2 = it;
			for (int i = 0; i < s; i++) {
				it = it2;
				b.push_back(*it);
				it2 = it;
				it2++;
				a.erase(it);
			}
			b.merge(a);
			a = b;
		}
		it = a.begin();
		cout << (*it) << endl;
	}
}

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

using namespace std;

int main(void)
{
	int n, r;
	while(cin >> n >> r && n!=0 && r != 0)
	{	
		vector<int> A(n);
		for(int i = 0;i < n; i++)
		{
			A[i] = n - i;
		}

		int p, c;

		for(int i = 0; i < r; i++)
		{
			cin >> p >> c;

			if(c != A.size() && ( (p + c - 1) != n ) )
			{
				rotate(A.begin(), A.begin() + A.size() - p, A.begin() + A.size() - p + c);
			}
			else if( (p + c - 1) == A.size() )
			{
				rotate( A.begin(), A.begin() + A.size() - c, A.end());
			}

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

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

int main(void){
    int n; 
    int r; 
    int p; 
    int c; 

    while(cin >> n >> r){
        if(n==0 && r==0)break;
        int card[n]; 
        int tmp[n]; 

        for (int i=n-1,number=1; i>=0; i--,number++){ 
            card[i] = number;
        }

        for (int i=0;i<n;i++){
            tmp[i] = 0;
        }

        for (int i=0;i<r;i++){
            cin >> p >> c;
            for(int j=0;j<p-1;j++){
                tmp[j] = card[j];
            }
            for(int j=0;j<c;j++){
                card[j] = card[j+p-1];
            }
            for(int j=0;j<p-1;j++){
                card[c+j]=tmp[j];
            }
        }
        cout << card[0] << endl;
    }
    return 0;
}

C++: #include <stdio.h>
int main()
{
  int k[51],i,n,r,y[51],a,b,ka,j;
  while(1){
    scanf("%d %d",&n,&r);
    if(n==0&&r==0)break;
    for(i=0;i<n;i++){
      k[i]=i+1;
      y[i]=i+1;
    }
    for(i=0;i<r;i++){
      scanf("%d %d",&a,&b);
      ka=1;
      for(j=0;j<b;j++){
	y[n-a-b+ka]=k[n-a-b+ka];
	ka++;
      }
      //printf("%d %d %d %d %d",k[0],k[1],k[2],k[3],k[4]);//
      ka=1;
      for(j=0;j<a-1;j++){
	k[n-a-b+ka]=k[n-a+ka];
	ka++;
      }
      ka=1;
      for(j=0;j<b;j++){
	k[n-b-1+ka]=y[n-a-b+ka];
	ka++;
      }
    }
    printf("%d\n",k[n-1]);
  }
  return 0;
}