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;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { 1, -1, 0, 0 };
static const int dy[] = { 0, 0, 1, -1 };

string str;
int n, r, p, c;

int gcd( int m, int n ) {
	if ( n == 0 ) return m;
	return gcd( n, m % n );
}


int main() {
	while ( ~scanf("%d %d", &n, &r) && n && r ) {
		str.resize( n + 2 );
		for ( int i = 0; i < n + 2; i++ ) {
			str[ i ] = n - ( i );
		}
		for ( int i = 0; i < r; i++ ) {
			scanf( "%d %d", &p, &c );
			str = str.substr( p - 1, c ) + str.substr( 0, p - 1 ) + str.substr( p + c - 1, str.size() - ( p + c - 1 ) );
		}
		printf( "%d\n", str[ 0 ] );
		str.clear();
	}
	return 0;
}

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

using namespace std;

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

int main(){
    int n,r,p,c; //r?????????????????°???p????????£?????????????????????????????????????????????c????????£???????????????????????°
    
    while(cin >> n >> r && n!=0 && r != 0){
        int cards[n];
        
        rep(i,n) cards[i] = n-i;
    
        //???????????£?????°
        rep(i,r){
            cin >> p >> c;
            rotate(cards, cards+p-1, cards+p-1+c);
            //rotate(??????????????????????????????,?????¢??°,??¨????????????????????????) *(start<=?<end)??????????????????+????????¨?????¢??°???-1?????????
        }
        
        cout << cards[0] << endl;
    }
}

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

int main(void)
{
	int yama[50];
	int d[50];
	while ( true ) {
		int n, r;

		std::cin >> n;
		std::cin >> r;

		if ( n == 0 && r == 0 ) break;

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

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

			int b = n - p;

			for ( int j = 0; j < c; ++j ) {
				d[c - j -1] = yama[b - j];
			}

			for ( int j = b; j < n; ++j ) {
				yama[j - c] = yama[j];
			}

			for ( int j = n - c; j < n; ++j ) {
				yama[j] = d[j - n + c];
			}
		}

		std::cout << yama[n - 1] << std::endl;
	}
	return 0;
}

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

int card[50];

void swap(int p,int c){
	int tmp[50];
	for(int i=0;i<c;i++)
		tmp[i]=card[i+p-1];
	for(int i=0;i<p-1;i++)
		tmp[i+c]=card[i];
	for(int i=0;i<p+c-1;i++)
		card[i]=tmp[i];
	return ;
}

int main(void){
	int n,r;
	while(cin >> n >> r,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;
			swap(p,c);
		}
		cout << card[0] << endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int input() {
	int input[51][2];
	cin >> input[0][0] >> input[0][1];								
	if (input[0][0] == 0 && input[0][1] == 0) {
		return 0;
	}
	for (char pos = 1; pos <= input[0][1]; pos++) {
		cin >> input[pos][0] >> input[pos][1];
	}																

	int whtop = 1;													
	whtop = input[input[0][1]][0];
	input[0][1]--;
	while (input[0][1] != 0) {

		if (input[input[0][1]][1] >= whtop) {
			whtop = input[input[0][1]][0] + whtop - 1;
		}
		else {
			whtop = whtop - input[input[0][1]][1];
		}
		input[0][1]--;
	}
	return input[0][0]-whtop+1;
}




int main()
{
	int output[1000];
	char topos = 0;
	while (1) {
		int check;
		check=input();
		if (check == 0)break;
		else {
			output[topos] = check;
			topos++;
		}
	}

	char sendpos = 0;
	while (sendpos < topos) {
		cout << output[sendpos] << endl;
		sendpos++;
	}


}

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;
      int da = 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;
	  
	  }
	else{
	  da = da-operate[i][0]+1;
	  if(da <= ans)ans+=operate[i][1];
	  //else if(da > ans)ans-=operate[i][1];

	}
	//cout << "da ~ " << da << endl;
	//cout << "ans = " << ans << endl;

      }

      cout << ans << endl;



    }

}

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

int n, r, p, c;
vector<int> cards(50);

void shuffle(int p, int c) {
    reverse(cards.begin(), cards.begin() + p);
    reverse(cards.begin() + p, cards.begin() + p + c);
    reverse(cards.begin(), cards.begin() + p + c);
}

int main() {
    while (1) {
        cin >> n >> r;
        if ( ! n && ! r) break;

        iota(cards.rend() - n, cards.rend(), 1);
        for (int i=0; i<r; ++i) {
            cin >> p >> c;
            shuffle(p - 1, c);
        }
        cout << cards[0] << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
	int n, r;
	vector<int> card;
	while(true){
		cin >> n >> r;
		if(!n && !r) break;
		card.clear();
		for(int i = 1; i <=n ; i++){
			card.push_back(i);
		}

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

			cin >> p >> c;
			if(n == c) continue;
			
			vector<int>::iterator it = card.end() - p - c + 1;

			for(int j = 0; j < c; j++){
				card.push_back(*it);
				it++;
			}
			card.erase(it  - c, it);
			
		}
		cout << card[n-1] << endl;
	}
	return 0;
}