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 first  fs
#define second se
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, char s = '\n') { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	int n, r;
	while (cin >> n >> r, n) {
		vi v;
		rep(i, n) v.push_back(n - i);

		rep(_, r) {
			int p = in(), c = in();
			vi beet, ei;
			for (int i = p - 1; i < p + c - 1; ++i) beet.push_back(v[i]);
			rep(i, p - 1) beet.push_back(v[i]);

			rep(i, p + c) v[i] = beet[i];
		}

		print(v[0]);
	}
}

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

void show(vector<int> a){
  for(int i=0;i<a.size();i++){
    cout << a[i] << endl;
  }
  cout << endl;
}
int main(){
  while(1){
    int N,R;
    cin >> N >> R;
    if(N==0&&R==0)break;
    vector<int> a;
    for(int i=N;i>=1;i--){
      a.push_back(i);
    }
    for(int i=0;i<R;i++){
      int p,c;
      cin >> p >> c ;
      vector<int> b;
      for(int j=0;j<c;j++){
        b.push_back(a[p-1+j]);
      }
      a.erase(a.begin()+p,a.begin()+p-1+c);
      a.insert(a.begin(),b.begin(),b.end());
    }
    cout << a[0] << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int x[100];
int y[100];
int card [100];
int n,r;
bool input(){
    for(int i=0;i<100;i++){
    x[i]=0;
    y[i]=0;
    }
    cin >>n>>r;
    for(int i=0;i<r;i++){
    cin>>x[i]>>y[i];
    }
    if(n==0){
    return false;
    }
    else{
     return true;
    }
}
void solve(){
    for(int i=0;i<100;i++){
        card[i]=i+1;
    }
    for(int i=0;i<r;i++){
        for(int k=0;k<y[i];k++){
            int a=card[x[i]+y[i]-2];
            for(int j=x[i]+y[i]-1;j>0;j--){
                card[j]=card[j-1];
            }
            card[0]=a;
           
        }
    for(int j=1;j<=y[i]/2;j++){
int remainder=card[j];
card[j]=card[y[i]-j];
card[y[i]-j]=remainder;
}
    }

    cout<<n-card[0]+1<<endl;
}
 
 
 
int main (){
    while(input()){
    solve();
    }
return 0;
}

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

int main()
{
	int n = 0;
	int r = 0;
	int p = 0;
	int c = 0;

	int deck[50] = {};
	int tmp[50] = {};

	while (true)
	{
		cin >> n;
		cin >> r;
		if (n == 0 && r == 0)break;
		for (int i = 0; i < n; i++)
		{
			deck[i] = n - i;
		}

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

			for (int j = 0; j < p - 1; j++)
			{
				tmp[j] = deck[j];
			}

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


			for (int j = 0; j < p - 1; j++)
			{
				deck[c + j] = tmp[j];
			}
		}
		cout << deck[0] << endl;
	}
	return 0;
}

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

int main(){
	int n,r;
	while(cin >> n >> r, n, r){
		int data[50], tmp[50];
		for(int i=0; i<n; i++){
			data[i]	= n-i;
			tmp[i] = n-i;
		}
		for(int i=0; i<r; i++){
			int p,c;
			cin >> p >> c;
			for(int j=0; j < p+c-1; j++){
				if(j<p-1){
					tmp[j+c] = data[j];
				}else{
					tmp[j-p+1] = data[j];
				}
			}
			for(int j=0; j<n; j++){
				data[j] = tmp[j];	
			}
		}
		cout << data[0] << endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( unsigned int i = (unsigned int)( m ); i < (unsigned int)( n ); i++ )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define RALL( c ) (c).rbegin(), (c).rend()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

VI shuffle( VI vec, int p, int c )
{
	VI res( vec.begin() + p, vec.begin() + p + c );
	vec.erase( vec.begin() + p, vec.begin() + p + c );
	res.insert( res.end(), ALL( vec ) );
	
	return res;
}

int main()
{	
	while ( true )
	{
		int n, r;
		cin >> n >> r;

		if ( !( n | r ) )
		{
			break;
		}

		VI res( n );
		REP( i, 0, n )
		{
			res[i] = n - i;
		}

		REP( i, 0, r )
		{
			int p, c;
			cin >> p >> c;

			res = shuffle( res, p - 1, c );
		}

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

	return 0;
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
using namespace std;

int main(){
	int n=1,r=1;
	int i,j;
	int c,p;
	cin>>n>>r;
	while(!(n==0&&r==0)){
		int x[100];
		queue<int> q;
	
	//cout<<n<<" "<<r<<endl;
	for(i=1;i<=n;i++){
		x[i] = i;
	}
	for(i=0;i<r;i++){
		cin>>p>>c;
		for(j=0;j<c;j++){
			q.push(x[n-p+1-j]);
		}
		for(j=0;j<p-1;j++){
			q.push(x[n-j]);
		}
		for(j=0;j<p+c-1;j++){
			x[n-j]=q.front();
			//cout<<q.front()<<endl;
			q.pop();
		}
	}
	cout<<x[n]<<endl;
		/*for(i=1;i<=n;i++){
			printf("%d\n",x[i]);
		}*/
		cin>>n>>r;
	}
	return 0;
}

C++: 
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	while(1) {
		int n, r, p, c;
		vector<int> cards;	//山札を意味するvector

		cin >> n >> r;		//山の枚数とシャッフル回数を取得する

		for(int i = n; i > 0; i --)
			cards.push_back(i);

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

		for(int i = 0; i < r; i++) {
			cin >> p >> c;
			vector<int> tmp;	//抜き取った札を一時的に記憶するvector

			//c枚の札を抜き取る
			for(int j = 0; j < c; j++)  
				tmp.push_back(cards.at(p - 1 + j));

			//p-1枚の札を下に移す
			for(int j = p - 2; j >= 0; j--)	
				cards.at(j + c) = cards.at(j);

			//c枚の札を上に戻す
			for(int j = 0; j < c; j++) 
				cards.at(j) = tmp.at(j);
		}

		//答えの出力
		cout << cards.at(0) << endl;
	}

	//while(1){}
	return 0;
}