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<stdio.h>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <functional>
#include <stdio.h>
#include <array>
#include <algorithm>
#include <string>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <queue>
#include<iomanip>
#include<bitset>
#include<stack>
#include<set>
#include<limits>
#include <complex>
using namespace std;

int dx[7] = { -1,0,1,0,-1,0,1 };
int dy[7] = { 0,1,0,-1,0,1,0 };

bool memo[64][16][4][64][16][4];


vector <vector<bool>>mp;

struct aa {
	int fx;
	int fy;
	int fway;
	int tx;
	int ty;
	int tway;
};
int gx, gy;

vector<aa>astack;

bool cangoal;

int gway;

bool check(int fx, int fy,int fway, int tx, int ty, int tway) {

	if (memo[fx][fy][fway][tx][ty][tway])return false;
	memo[fx][fy][fway][tx][ty][tway] =true;
	
	//else{

		int nfy = fy + dy[fway];
		int nfx = fx + dx[fway];
		while (1) {
			
			if (mp[nfy][nfx]) {
				nfx -= dx[fway];
				nfy -= dy[fway];
				break;
			}
			nfy = nfy + dy[fway];
			nfx = nfx + dx[fway];

		}

		int nty = ty;
		int ntx = tx;
		while (1) {

			if (mp[nty][ntx]) {
				ntx -= dx[tway];
				nty -= dy[tway];
				break;
			}

			if (mp[nty + dy[tway + 1]][ntx + dx[tway + 1]]) {
				int afway = (fway + 3) % 4;
				int atway = (tway + 3) % 4;
				if (nfx == gx&&nfy == gy&&ntx == gx&&nty == gy) {
					if (tway == (gway + 2) % 4)
						return true;
				}
				if (fx == gx&&fy == gy) {
					cangoal = true;
				}
				if (!memo[nfx][nfy][afway][ntx][nty][atway]) {
					astack.push_back(aa{ nfx,nfy,afway,ntx,nty,atway });
				}
			}

			if (mp[nty + dy[tway + 3]][ntx + dx[tway + 3]]) {
				int afway = (fway + 1) % 4;
				int atway = (tway + 1) % 4;
				if (nfx == gx&&nfy == gy&&ntx == gx&&nty == gy) {
					if (tway == (gway + 2) % 4)
						return true;
				}
				if (fx == gx&&fy == gy) {
					cangoal = true;
				}
				if (!memo[nfx][nfy][afway][ntx][nty][atway]) {
					astack.push_back(aa{ nfx,nfy,afway,ntx,nty,atway });
				}
			}

			nty = nty + dy[tway];
			ntx = ntx + dx[tway];
		}
		if (mp[nty + dy[tway + 1]][ntx + dx[tway + 1]]) {
			int afway = (fway + 3) % 4;
			int atway = (tway + 3) % 4;
			if (nfx == gx&&nfy == gy&&ntx == gx&&nty == gy) {
				if (tway == (gway + 2) % 4)
					return true;
			}
			if (fx == gx&&fy == gy) {
				cangoal = true;
			}
			if (!memo[nfx][nfy][afway][ntx][nty][atway]) {
				
				astack.push_back(aa{ nfx,nfy,afway,ntx,nty,atway });
			}
		}

		if (mp[nty + dy[tway + 3]][ntx + dx[tway + 3]]) {
			int atway = (tway + 1) % 4;
			int afway = (fway + 1) % 4;
			if (nfx == gx&&nfy == gy&&ntx == gx&&nty == gy) {
				if (tway == (gway + 2) % 4)
					return true;
			}
			if (fx == gx&&fy == gy) {
				cangoal = true;
			}
			if (!memo[nfx][nfy][afway][ntx][nty][atway]) {	
				astack.push_back(aa{ nfx,nfy,afway,ntx,nty,atway });

			}
		}

	//}
	return false;
}

bool memo2[64][16][4];

bool check2(int fx, int fy, int fway) {
	if (memo2[fx][fy][fway])return false;
	memo2[fx][fy][fway] = true;

	if (fx == gx&&fy == gy)return true;
	int nfy = fy + dy[fway];
	int nfx = fx + dx[fway];
	while (1) {

		if (mp[nfy][nfx]) {
			nfy -= dy[fway];
			nfx -= dx[fway];
			break;
		}
		nfy = nfy + dy[fway];
		nfx = nfx + dx[fway];
	}
	return (check2(nfx, nfy, (fway + 1) % 4) || check2(nfx, nfy, (fway + 3) % 4));
}

int main() {
	while (1) {
		int n, r; cin >> n >> r;
		if (!n)break;
		vector<int>ya(n);
		for (int i = 0; i < n; ++i) {
			ya[i] = n-(i);
		}
		for (int i = 0; i < r; ++i) {
			int p, c; cin >> p >> c;
			vector<int>nya(ya);
			for (int i = 0; i < c; ++i) {
				nya[i] = ya[p-1 + i];
			}
			for (int i =c; i < c+p-1; ++i) {
				nya[i] = ya[i-c];
			}
			ya = nya;
		}
		cout << ya[0] << endl;
	}

	return 0;
}

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

using namespace std;

int solve(int n,int r){
    vector<pair<int,int> >p;
    for(int i=0;i<r;i++){
        int a,b;
        cin >> a >> b;
        p.push_back(make_pair(a,b));
    }

    reverse(p.begin(),p.end());
    int x = n;
    for(vector<pair<int,int> >::iterator it=p.begin();
        it != p.end();
        ++it){
        int a = (*it).first;
        int b = (*it).second;
        if(x >= (n-b+1)){
            x = x - (a-1);
        }else if(x >= (n-b)-(a-1)+1){
            x = x + b;
        }
    }
    cout << x << endl;
}

int main(){
    int n,r;
    while(cin >> n >> r){
        if(n==0 && r==0){
            break;
        }
        solve(n,r);
    }
    return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int deck[51] = {0};
	int n=0;
	int r=0;
	int p[51] = {0};
	int c[51] = {0};
	int downs[51] = {0};
	int ups[51] = {0};
	int i,j;
	int endflag = 0;
	int out[1000]={0};
	int outc=0;

	while(1)
	{
		
		scanf("%d",&n);
		scanf("%d",&r);

		if(n == 0 && r == 0)
		{
			for( i = 0; i < outc ; i++)
				printf("%d\n",out[i]);

			return 0;
		}

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



		for(i = 1 ; i < n + 1 ; i++)
		{
			deck[i-1] = n + 1 - i;
		}


		for( j = 0 ; j < r ; j++)
		{
			for(i = 0 ; i < p[j] - 1 ; i++)
			{
				downs[i] = deck[i];
			}
			for(i = 0 ; i < c[j]  ; i++)
			{
				ups[i] = deck[i+p[j]-1];
			}

			for(i = 0 ; i < c[j] ; i++)
			{
				deck[i] = ups[i];
			}
			for(i = 0 ; i < p[j] - 1 ; i++)
			{
				deck[i+c[j]] = downs[i];
			}

			for(i = 0; i < p[j] + c[j] - 1 ; i++)
			{
				ups[i] = 0;
				downs[i] = 0;
			}

		}

		out[outc] = deck[0];
		outc++;

		for(i = 0; i < 50; i++)
			{
				deck[i] = 0;
				p[i] = 0;
				c[i] = 0;
			}


	}


}

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

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

  while(cin >> n >> r , n + r){
    vector<int> cards;

    for(int i = n ; i >= 1 ; i--){
      cards.push_back(i);
    }

    while(r--){
      cin >> p >> c;
      vector<int> tmp;
      for(int i = p-1 ; i < p+c-1 ; i++){
	tmp.push_back(cards[i]);
      }
   
      for(int i = 0 ; i < cards.size() ; i++){
	tmp.push_back(cards[i]);
      }
      for(int i = 0 ; i < n ; i++){
	cards[i] = tmp[i];
      }

    }
    cout << cards[0] << endl;
  }

  return 0;
}

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

int main(){
    int n,r,p,c;
    while(cin >> n >> r, n&&r){
        vector<int> cards;
        for(int i = 0; i < n; i++){
            cards[i] = n - 1;
        }
        while(r--){
            cin >> p >> c;
            vector<int> cpCards = cards;
            int pos = 0;
            for(int i = p - 1; i < p - 1 + c; i++){
                cards[pos] = cpCards[i];
                pos++;
            }
            for(int i = 0; i < p - 1; i++){
                cards[pos] = cpCards[i];
                pos++;
            }
        }
        cout << cards.front() << endl;
    } 
}

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

int main(void)
{

	int n,r;
	int p,c;
	int i1,i2;

	
	cin << n << r;

	

	vector<int> fuda(n),temp(n);

	/* syokika */
	for(i1=0;i1<n;i1++){
		fuda[i1] = i1+1;
//		cout << fuda[i1] << " ";

	}

	/* copy */
	for(i1=0;i1<p-1;i1++){
		temp[i1] = fuda[i1];
	}


	/* shuffle */
	for(i1=0;i1<c;i1++){
		fuda[i1] = fuda[p-1+i1];
	}
	for(i1=c;i1<p-1+c;i1++){
		fuda[i1] = temp[i1-c];
	}


	for(i1=0;i1<n;i1++){
		cout << fuda[i1] << " ";
	}

	return 0;
}