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 <iostream>

#define N (20)

#define BLACK   (0)
#define RED     (-1)

using namespace std;

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

int main(void)
{
	int m[N][N];
	int w, h;

	while(cin >> w >> h) {
		if(w == 0 && h == 0) break;

		for(int j = 0; j < h; j++) {
			for(int i = 0; i < w; i++) {
				char c;
				cin >> c;
				m[i][j] = (c == '#') ? RED : BLACK;
				if(c == '@') m[i][j] = 1;
			}
		}

		int sol = 1;
		int n = 1;
		bool flag = true;

		while(flag) {
			flag = false;
			for(int j = 0; j < h; j++) {
				for(int i = 0; i < w; i++) {
					if(m[i][j] != n) continue;
					for(int dir = 0; dir < 4; dir++) {
						int x = i + dx[dir];
						int y = j + dy[dir];
						if(x < 0 || x >= w || y < 0 || y >= h) continue;
						if(m[x][y] != BLACK) continue;
						m[x][y] = n;
						++sol;
						flag = true;
					}
				}
			}
		}

		cout << sol << endl;
	}

	return 0;
}

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

int main(){
  int n, r, p, c, l[50];

  while(cin >> n >> r, n | r){
    for(int i=0;i<n;i++)
      l[i]=n-i;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      rotate(l,l+p-1,l+p+c-1);
    }
    cout<<l[0];
  }

  return 0;
}

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

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

C++: #include <stdio.h>
int n, r, p, c, d[50], e[50];
int main() {
	while (true) {
		scanf("%d%d", &n, &r);
		if (n == 0 && r == 0) break;
		for (int i = 0; i < n; i++) d[i] = n - i;
		for (int i = 0; i < r; i++) {
			scanf("%d%d", &p, &c);
			for (int j = 0; j < c; j++) {
				e[j] = d[j + p];
			}
			for (int j = c; j < p + c; j++) {
				e[j] = d[j - p];
			}
			for (int j = 0; j < p + c; j++) {
				d[j] = e[j];
			}
		}
		printf("%d\n", d[0]);
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
using namespace std;

int main()
{
  int n,r;
  int i,j,k;
  int p,c;
  int a[60];//a[0]??????
  int b[60];
  int x;

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

    for(i=0;i<r;i++){
      cin>>p>>c;
      for(j=0;j<c;j++)//c??????????????????
	b[j]=a[p-1+j];
      for(k=0;k<p-1;k++)//p-1???????????¨???
	b[j+k]=a[k];
      for(x=0;x<j+k;x++)//??????????????????
	a[x]=b[x];      
    }    
    cout<<a[0]<<endl;
  }
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <random>

// boost
//#define USE_BOOST_IN_CODE
#ifdef USE_BOOST_IN_CODE
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/strided.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/format.hpp>
#endif


using ll = long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vv = vec<vec<T>>;

//namespace std
//{
//    template<>
//    class hash<Key>
//    {
//    public:
//        size_t operator() (const Key& key) const
//        {
//            size_t seed = 0;
//            auto i_hash = hash<int>()(key.i_th);
//            auto w_hash = hash<int>()(key.W);
//
//            seed ^= i_hash + 0x9e3779b9 + (seed << 6) + (seed >> 2);
//            seed ^= w_hash + 0x9e3779b9 + (seed << 6) + (seed >> 2);
//
//            return seed;
//        }
//    };
//}

void solve()
{
    using namespace std;
    int n;

    while (cin >> n)
    {
        if (n == 0)
            break;

        int r;
        cin >> r;
        vec<int> deck;
        for (int i = 0; i <= n; ++i)
            deck.push_back(i);

        while (r-- != 0)
        {
            vec<int> newDeck {};
            int p, c;
            cin >> p >> c; 

            auto binserter = back_inserter(newDeck);

            copy(deck.cbegin(), deck.cend() - p + 1 - c, binserter);
            copy(deck.cend() - p + 1, deck.cend(), binserter);
            copy(deck.cend() - p + 1 - c, deck.cend() - p + 1, binserter);

            deck = newDeck;
        }

        cout << deck[deck.size() - 1] << endl;
    }

}

int main()
{
    solve();
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
typedef long long i64;
int main(){
    int n,r,p,c;
    while (true) {
        /* code */
        cin >> n >> r;
        if(n==0 && r==0) break;
        int hanafuda[n];
        rep(i,n) hanafuda[i]=n-i;
        rep(i,r){
            cin >> p >> c;
            int cs[c];
            rep(j,c){
                cs[j]=hanafuda[p+j-1];
            }
            for(int j=p-2;j>=0;j--){
                hanafuda[j+c]=hanafuda[j];
            }
            rep(j,c){
                hanafuda[j]=cs[j];
            }
        }
        cout << hanafuda[0] << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

void change(int deck[], int s, int e) {
	int t[50];
	for (int i = 0; i < e; i++) {
		t[i] = deck[i];
	}
	for (int i = 0; i < s; i++) {
		deck[i - s + e] = t[i];
	}
	for (int i = 0; i < e - s; i++) {
		deck[i] = t[i + s];
	}
}

int main()
{
	int deck[50];
	int n, r, s, e;
	while (true) {
		cin >> n >> r;
		if (n == 0 && r == 0) break;
//		cout << n << r << endl;
		for (int i = 0; i < 50; i++) deck[i] = n - i - 1;
		for (int i = 0; i < r; i++) {
			cin >> s >> e;
			change(deck, s - 1, e + s - 1);
		}
		cout << deck[0] + 1 << endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <iostream>
using namespace std;
int N,R,p,c;
int A[50] = {};
int main(void) {
	while (cin >> N >> R && N) {
		for (int i=0; i<N; ++i) A[i] = N-i;
		for (int i=0; i<R; ++i) {
			cin >> p >> c;
			rotate (A,A+p-1,A+p+c-1);
		}
		cout << A[0] << endl;
	}
}

C++: #include <stdio.h>

int main(){

  int n,r,p,c,i,j;
  int score[51];
  int temp[51];

  for(;;){

    scanf("%d%d",&n,&r);
    if(n==0&&r==0){
      break;
    }

    for(i=1;i<=n;i++){
      score[i]=i;
      temp[i]=i;
    }

    for(i=1;i<=r;i++){
      scanf("%d%d",&p,&c);

      for(j=n-p+1;j>n-p+1-c;j--){
	score[j+p-1]=score[j];
      }
      for(j=n;j>=n-p+1;j--){
	score[j-c]=temp[j];
      }

    }

    printf("%d\n",score[n]);
  }
  return 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;
}