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 <cstdio>
#include <utility>
#include <stack>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
//void scan(string &s) {for (char c; !isspace(c = gcu()); s += c);}
inline bool scan(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
#undef svo

struct operation {int p, c;};

int main() {
	int n, r;
	while (scan(n) && scan(r) && (n || r)) {
		stack<operation> op;
		while (r--) {
			int p = in(), c = in();
			op.push({p, c});
		}
		int top = 1;
		while (!op.empty()) {
			auto o = op.top();
			op.pop();
			if (top <= o.c)
				top += o.p - 1;
			else if (top - o.c < o.p)
				top -= o.c;
		}
		out(n - top + 1, '\n');
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int main(){
  int n,r;
  while(1){
    cin>>n>>r;
    if(n==0&&r==0)break;
    int d[51];
    //?????????
    for(int i=0;i<n;i++){
      d[i]=n-i;
    }

    if(debug)for(int i=0;i<n;i++)cout<<d[i]<<" ";
    if(debug)cout<<endl;
      
    for(int i=0;i<r;i++){
      int p,c,tmp[51];
      cin>>p>>c;
      
      for(int j=0;j<c;j++)tmp[j]=d[j+p-1];

      for(int j=p-2;j>=0;j--)d[j+c]=d[j];

      for(int j=0;j<c;j++)d[j]=tmp[j];

      
      if(debug)for(int i=0;i<n;i++)cout<<d[i]<<" ";
      if(debug)cout<<endl;
    }
    
  }
  return 0;
}

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

int main()
{
	int n,r;
	while(cin>>n>>r){
		if(n==0) return 0;
		vector<int> V;
		for(int i=0;i<n;i++)
			V.push_back(n-i);

		for(int i=0;i<r;i++){
			int s,t;
			cin>>s>>t;
			s--;

			vector<int> w;
			for(int j=0;j<t;j++){
				w.push_back(V[s+j]);
			}

			vector<int> next;

			for(int k=0;k<w.size();k++){
				next.push_back(w[k]);
			}

			for(int k=0;k<s;k++){
				next.push_back(V[k]);
			}

			for(int k=s+t;k<n;k++)
				next.push_back(V[k]);

			V=next;
		}
		cout<<V[0]<<endl;


	}
}

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

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long

//constant
const int MOD = 1000000009;
const int INF = INT_MAX / 3;

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
	int n, r;
	while (cin >> n >> r, n) {
		vi st(n);
		REP(i, n)
			st[i] = n-i ;

		REP(i, r) {
			vi sw(n);
			REP(i, n)
				sw[i] = st[i];
			int p, c;
			cin >> p >> c;
			REP(j, c)
				sw[j] = st[p-1  + j];
			REP(j, p-1)
				sw[j + c] = st[j];


			REP(i, n)
				st[i] = sw[i];

		}

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

	return 0;
}

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

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

	while(1){
		cin >> n >> r;

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

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

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

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

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

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

		}

		cout << yama[n-1] << endl;
	}
}

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

int deck[64], buf[64];

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

	for (int i = 0; i < n; i++){
	    deck[i] = n - i; buf[i] = n - i;
	}

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

	    // for blue
	    for (int j = 0; j < p-1; j++){
		buf[c+j] = deck[j];
	    }
	    // for orange
	    for (int j = 0; j < c; j++){
		buf[j] = deck[p-1+j];
	    }
	    for (int j = p + c - 1; j < n; j++){
		buf[j] = deck[j];
	    }

	    for (int m = 0; m < n; m++) deck[m] = buf[m];
	}
	cout << deck[0] << endl;

    }
}

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


using namespace std;

int main(void){


    int n,r;
    while(scanf("%d %d", &r, &n), n){
        int p,c;
        int x[128], y[128];
        for(int i = 0; i < r; i++){
            y[i] = r-i;
        }

        for(int i = 0; i < n; i++){
            int cnt = 0;
            for(int j = 0; j < r; j++)x[j] = y[j];


            scanf("%d %d", &p, &c);

            for(int j = p-1; j < p+c-1; j++){
                y[cnt] = x[j];
                cnt++;
                x[j] = -1;
            }

            for(int j = 0; j < r; j++)if(x[j] != -1){y[cnt] = x[j];cnt++;}
//            for(int j = 0; j < r ; j++)printf("%2d:%2d\n", x[j], y[j]);
        }

        for(int j = 0; j < r; j++)x[j] = y[j];
        printf("%d\n", x[0]);
    }
    return 0;
}

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

void show_v( vector<int> v ){
    for(vector<int>::iterator it=v.begin(); it!=v.end(); it++){
        cout << *it << ' ';
    }
    cout << endl;
}

int main(){
    int n, r, i, j, p, c;
    while( cin >> n >> r, n||r ){
        vector<int> card(n);
        for(i = 0; i < n; i++){
            card[i] = n-i;
        }
        while( r-- > 0 ){
            cin >> p >> c;
            vector<int> tmp;
            tmp.assign( card.begin()+p-1, card.begin()+p+c-1 );
            card.erase( card.begin()+p-1, card.begin()+p+c-1 );
            tmp.insert( tmp.end(), card.begin(), card.end() );
            card.assign( tmp.begin(), tmp.end() );
        }
        cout << card[0] << endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

   while(1){

      int n, r;
      cin>> n>> r;
      if(n==0&&r==0) break;
      int a[n];
      for(int i=0; i<n; i++) a[i]=n-i;
      for(int i=0; i<r; i++){
         int p, c;
         cin>> p>> c;
         int b[c];
         for(int j=p-1; j<p+c-1; j++){
            b[j-(p-1)]=a[j];
         }
         for(int j=p+c-2; j>c-1; j--){
            a[j]=a[j-c];
         }
         for(int j=0; j<c; j++){
            a[j]=b[j];
         }
      }

      cout<< a[0]<< endl;
   }
   return 0;
}