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 <iostream>
#include <deque>
#include <vector>

using namespace std;

int main( void ){
	vector< int > result;
	deque< int > card;
	while( true ){
		int n, r;
		cin >> n >> r;
		if( n == 0 && r == 0 )
			break;
		for( int i = 1; i < n + 1; i++ ){
			card.push_front( i );
		}
		for( int i = 0; i < r; i++ ){
			int p, c;
			cin >> p >> c;
			for( auto itr = card.begin(); itr != card.end(); ++itr ){
				if( ( *itr ) <= p ){
					int temp = ( *itr );
					card.erase( itr );
					card.push_front( temp );
				}
			}
		}

		result.push_back( card.front() );
			
	}

	for( auto itr = result.begin(); itr != result.end(); ++itr ){
		cout << ( *itr ) << endl;
	}

	return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n,r,p,c;
	while(cin >> n >> r, n+r){
		int huda[n];
		for(int i=0; i<n; i++){
			huda[i]	= n-i;
		}
		for(int i=0; i<r; i++){
			cin >> p >> c;
			int tmp[c];
			for(int j=0; j<c; j++){
				tmp[j] = huda[p+j-1];
			}
			for(int j=p-2; j>=0; j--){
				huda[j+1] = huda[j];
			}
			for(int j=0; j<c; j++){
				huda[j]=tmp[j];	
			}
		}
		cout << huda[0] << "\n";
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <array>

using namespace std;

int A[51];
int n,m,p,c;

int main(){
    while(true){
        cin >> n >> m;
        if(n+m == 0)break;
        for(int i = 0;i < n;i++)A[i] = n - i;
        for(int i = 0;i < m;i++){
            cin >> p >> c;
            rotate(A,A+p-1,A+p+c-1);
//            for(int k = 0;k < n;k++){
//                cout << A[k] << " ";
//            }
//            cout << endl;
        }
        cout << A[0] << endl;
    }
}

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

#define rep(a, b, c) for(int a = b; a < c; a++ )

using namespace std;

int main() {
    while (true) {
        int N, R;
        cin >> N >> R;
        if (N == 0 && R == 0) break;
        int yama[N];
        rep(i, 0, N) {
            yama[i] = N - i;
        }
        rep(i, 0, R) {
            int P, C;
            cin >> P >> C;
            int rem[C];
            rep(j, 0, C) {
                rem[j] = yama[j + P - 1];
            }
            for (int j = P - 2; j >= 0; j--) {
                yama[j + C] = yama[j];
            }
            rep(j, 0, C) {
                yama[j] = rem[j];
            }
        }
        cout << yama[0] << endl;
    }
    return 0;
}

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

int main(void) {
	int n, r;

	while(cin >> n >> r, n || r) {
		vector<int> deck;
		
		for(int i = 0; i < n; i++) {
			deck.push_back(n - i);
		}

		for(int j = 0; j < r; j++) {
			int p, c;
			cin >> p >> c;
			vector<int> tmp(deck.begin(), deck.begin() + p);
			for(int k = 0; k < c; k++) {
				deck[k] = deck[p - 1 + k];
			}

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

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

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
	int n,m;
	while(cin>>n>>m,n,m){
		string str;
		for(int i=n;i>0;i--)str+=i;
		for(int i=0,p,c;i<m;i++){
			string now;
			cin>>p>>c;
			for(int j=0;j<c;j++)now+=str[p-1+j];
			for(int j=0;j<n;j++)if(j<p-1||j>p+c-2)now+=str[j];
			str=now;
		}
		cout<<str[0]<<endl;
	}
}

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

int main(){

  int card[50];
  int esc[50];
  int n,r;
  int p,c;

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

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

      /*
      cout << "prev:";
      for(int j=0; j<n; j++)cout << card[j] << ' ';
      cout << endl;
      */

      for(int j=0; j<c; j++){
	esc[j] = card[p-1+j];
      }
      for(int j=p-2; j>=0; j--){
	card[j+c]=card[j];
      }
      for(int j=0; j<c; j++){
	card[j] = esc[j];
      }

      /*cout << "now:";
      for(int j=0; j<n; j++)cout << card[j] << ' ';
      cout << endl;
      cout << "esc:";
      for(int j=0; j<c; j++)cout << esc[j] << ' ';
      cout << endl;
      */
   }

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

  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int n,m;
struct cards
{
    int from,to;
    cards(int f,int t)
    {
        from=f,to=t;
    }
};
deque<cards> all;
deque<cards> split(int k)
{
    deque<cards> sub;
    for(;;)
    {
        cards t=all.front();
        all.pop_front();
        k -= t.to-t.from+1;
        if(k==0)
        {
            sub.pb(t);
            break;
        }
        if(k<0)
        {
            all.push_front(cards(t.to+k+1,t.to));
            t.to+=k;
            sub.pb(t);
            break;
        }
        sub.pb(t);
    }
    return sub;
}
void print(deque<cards> mount)
{
	for(int i=0;i<mount.size();i++)
	{
		cout << mount[i].from << ' ' << mount[i].to << endl;
	}
	return;
}
void shuffle(int x,int y)
{
    deque<cards> a=split(x);
    deque<cards> b=split(y);
    for(int i=a.size()-1;i>=0;i--)all.push_front(a[i]);
    for(int i=b.size()-1;i>=0;i--)all.push_front(b[i]);
}
int main()
{
    while(1)
    {
        cin >> n >> m;
        if(n==0&&m==0)break;
        all.clear();
        all.pb(cards(1,n));
        for(int i=0;i<m;i++)
        {
            int p,c;
            cin >> p >> c;
            shuffle(p-1,c);
        }
        cout << n-all[0].from+1 << endl;
    }
    return 0;
}

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

int main(){
	int n,r;
	while((cin >> n)&&(cin >> r)&&(n!=0)&&(r!=0)){
		int a[n];
		int cnt=n;
		for(int i=0;i<n;i++){
			a[i] = cnt;
			cnt--;
			//cout << "a[" << i << "]" << a[i] << endl;
		}
		int p,c;
		//cout << endl;
		for(int i=0;i<r;i++){
			cin >> p;
			cin >> c;
			int b[50];
			//cout << p << endl;
			//cout << c << endl;
			//cout << endl;
			if(n!=c){
				for(int j=0;j<p;j++){
					b[j+c] = a[j];
				}
				for(int j=0;j<c;j++){
					b[j] = a[p+j-1];	
				}
				for(int j=0;j<p+c;j++){
					a[j] = b[j];	
					//cout << "a[" << j << "]" << a[j] << endl;
				//	cout << "b[" << j << "]" << b[j] << endl;
				}
			}
		}
		cout << a[0] << endl;
	}
}