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 inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265


void f(int n,int r){
  int a[100];
  rep(i,n){
    a[i+1]=n-i;
  }

  rep(i,r){
    int p,c;
    cin>>p>>c;
    int b[100];
    rep(j,p){
      b[j]=a[j+1];
    }
    rep(j,c){
      a[j+1]=a[p+j];
    }
    rep(j,p){
      a[j+c+1]=b[j];
    }
    
  }

  cout<<a[1]<<endl;

}

int main(){
  while(1){
    int n,r;
    cin>>n>>r;
    if(n==0) break;
    f(n,r);
  }

  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <cstring>

using namespace std;
const int INF = (1<<30);
typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for (int i = 0; i < a; i++)

int sx, sy;

int gx, gy;

int qqq;

//各座標までの最短距離
int d[100][100];


//移動方向のベクトル
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

//汎用
ll ans = 0;
pair<int, int> red[101], blue[101];
ll BIG = 10000000000;

//累乗
ll POW(ll a, ll b) {
ll c = 1;
for (int i = 0; i < b; ++i) {
c *= a;
}
return c;
}

//階乗
int Kaijou(int a) {
if (a < 2) return 1;
return a * Kaijou(a - 1);
}


int A[200000];
int kinds[200001];


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

		vector<int> s(n);
		iota(s.begin(), s.end(), 1);
		reverse(s.begin(), s.end());

		rep(i, r) {
			int p, c;
			cin >> p >> c;
			int toU[100] = { 0 }, toD[100] = { 0 };
			rep(i, c) {
				toU[i] = s[p - 1 + i];
			}
			rep(i, p - 1) {
				toD[i] = s[i];
			}
			rep(i, c) {
				s[i] = toU[i];
			}
			rep(i, p - 1) {
				s[i + c] = toD[i];
			}
		}
	
		cout << s[0] << endl;
	}
	cin >> qqq;
}

C++: 
#include<cstdio>
#include<iostream>
#include<string>
#include <algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<set>
using namespace std;
using ll = long long;

int n, r, a, b;
int t[100];
int u[100], size;
int main() {
	while (cin >> n >> r && n&&r) {
		for (int i = 0; i<n; i++)t[i] = n - i;
		for (int i = 0; i<r; i++) {
			cin >> a >> b;
			for (int j = 0; j<b; j++)u[j] = t[j + a - 1];
			for (int j = a - 2; j >= 0; j--)t[j + b] = t[j];
			for (int j = 0; j<b; j++)t[j] = u[j];
		}
		cout << t[0] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int n,r;
	while(cin>>n>>r and n>0){
		int a[n]; rep(i,n) a[i]=n-i;
		rep(i,r){
			int p,c; cin>>p>>c;
			rotate(a,a+p-1,a+p+c-1);
		}
		cout<<a[0]<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, r, p, c;
    while (true) {
        cin >> n >> r;
        if (n == 0 && r == 0) {
            break;
        }
        vector<int> deck;
        for (int i = 0; i < n; i++) {
            deck.push_back(i + 1);
            // cout << deck[i] << endl;
        }
        for (int i = 0; i < r; i++) {
            cin >> p >> c;
            stack<int> s;
            for (int j = 0; j < c; j++) {
                // cout << "要素番号" << deck.size() - p - j << endl;
                s.push(deck[deck.size() - p - j]);
                // cout << "取り除いたもの" << s.top() << endl;
            }
            // cout << s.top() << endl;
            deck.erase(deck.begin() + (deck.size() - p - c + 1), deck.begin() + (deck.size() - p + 1));

            for (int j = 0; j < c; j++) {
                deck.push_back(s.top());
                s.pop();
            }
            // for (int afa = 0; afa < deck.size(); afa++) {
            //     cout << deck[afa] << endl;
            // }
        }
        cout << deck[deck.size() - 1] << endl;
    }
}

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

int main(){
  int n, r;
  while(cin >> n >> r && n){
    // cout << "n" << n << "r" << r <<endl;
    // ?±±?????????
    vector<int> fuda(n,0);
    for(size_t i=0; i<fuda.size(); i++) fuda[fuda.size()-1-i] = i+1;
    for(int i=0; i<r ; i++){
      int p, c;
      cin >> p >> c;
      // ?????£???????????????
      rotate(fuda.begin(),fuda.begin()+(p-1),fuda.begin()+(p-1)+c);  
      // for(size_t j=0 ; j<fuda.size(); j++) cout << fuda[j] << " ";
      // cout << endl;
    }
    cout << fuda[0] << endl;
  }
}

C++: #include<stdio.h>
 
int main(void)  {
    int n,r,p,c;
 
    while(1)    {
        scanf("%d %d", &n, &r);
        if(n == 0) break;
 
        int card[n];
        int temp[n];
        for(int i = 0;i <= n - 1;i++)   card[i] = n - i;
 
        for(int i = 0;i <= r - 1;i++)   {
            scanf("%d %d", &p, &c);
 
            int count = 0;
            for(int i = p - 1;i <= p + c - 2;i++)   {
                temp[count] = card[i];
                count++;
            }

            for(int i = 0;i <= p - 2;i++)   {
                temp[count] = card[i];
                count++;
            }
 
            for(int i = p + c - 1;i <= n - 1;i++)   {
                temp[count] = card[i];
                count++;
            }

            for(int i = 0;i <= n - 1;i++)   {
                card[i] = temp[i];
            }
        }
 
        printf("%d\n", card[0]);
    }
     
    return 0;
}

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

int main(void)
{
	while ( true ) {
		std::vector<int> yama;
		int n, r;

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

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

		yama.resize(n);

		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;

			std::vector<int> d(c);

			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>
#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();
		// 1 .. n
		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;
			
			// temp
			for(int j = 0; j < c; j++){
				card.push_back(*it);
				it++;
			}
			//erase
			card.erase(it  - c, it);
		}
		cout << card[n-1] << endl;
	}
	return 0;
}