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 iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

int count(vector<int> ls, int x) {
  const int n = ls.size();
  int left;
  int right;

  {{{ // search left
    if (ls[0] == x) {
      left = 0;
    } else {
      int l = 0;
      int r = n;
      // ls[l] < x <= ls[r]
      while (l < r) {
        if (l + 1 == r) {
          if (ls[l] == x) left = l;
          else if (ls[r] == x) left = r;
          else return 0;
          break;
        }
        int m = (l + r) / 2;
        if (ls[m] < x) {
          l = m;
        } else {
          r = m;
        }
      }
    }
  }}}

  {{{ // search right
    if (ls[n-1] == x) {
      right = n;
    } else {
      int l = 0;
      int r = n;
      // ls[l] <= x < ls[r]
      while (l < r) {
        if (l + 1 == r) {
          if (ls[l] == x) right = r;
          else if (ls[r] == x) right = r + 1;
          else return 0;
          break;
        }
        int m = (l + r) / 2;
        if (ls[m] <= x) {
          l = m;
        } else {
          r = m;
        }
      }
    }
  }}}

  return right - left;
}

int main() {

more:;
   int n, m; cin >> n >> m;
   if (!n && !m) return 0;

   vector<int> xs(n+2, -1);
   rep (i, n) xs[i] = n - i;

   rep (i, m) {
     int c, p; cin >> p >> c;
     rotate(xs.begin(), xs.begin() + p - 1, xs.begin() + c + p - 1);
   }
   cout << xs[0] << endl;
   goto more;

  return 0;
}

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

int main(){
	int p[50], c[50], n, r, pos, i;
	for( ; cin >> n >> r, n; ){
		for( i = 0; i < r; ++i ){
			cin >> p[i] >> c[i];
		}

		pos = 0;
		for( i = r; i--; ){
			if( pos < c[i] ){
				pos += p[i] - 1;
			}
			else if( pos < c[i] + p[i] - 1 ){
				pos -= c[i];
			}
		}
		cout << n - pos << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int N, R, p, c;
int main() {
  while (cin >> N >> R && N){
    vector<int> A(N,0);
    int i;
    for(i=0;i<N;i++){
      A[i]=N-i;
    }
    for(i=0;i<R;++i){
      cin >> p >> c;
      if (p==0){
        cout << "Incorrect input" << endl;
        exit(1);
      }
      rotate(A.begin(),A.begin()+p-1,A.begin()+p+c-1);
    }
    cout << A[0] << endl;
  }
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
const double PI=acos(-1.0);
//---------------------------------------------------------------------------//
int n,r;
int a[51],b[51],c[51];
int main(){
        while(1) {
                cin>>n>>r;
                if(n==0 && r==0) {
                        return 0;
                }
                for(int i=0; i<r; i++) {
                        cin>>a[i]>>b[i];
                }

                for(int i=0; i<n; i++) {
                        c[i]=i;
                }
                for(int i=0; i<r; i++) {
                        for(int j=0; j<a[i]-1; j++) {
                                c[j]+=b[i];
                        }
                        for(int j=a[i]-1; j<a[i]-1+b[i]; j++) {
                                c[j]-=(a[i]-1);
                        }
                }
                for(int i=0; i<n; i++) {
                        if(c[i]==0) {
                                cout<<n-i<<endl;
                        }
                }
        }
}

C++: #include<bits/stdc++.h>
#define INF INT_MAX/2
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

char a[50], b[50];
int main() {
	int n, r;
	while (scanf("%d%d", &n, &r), n) {
		for (int i = n - 1; i >= 0; i--)a[i] = n - i;
		rep(i, r) {
			int p, c; scanf("%d%d", &p, &c);
			memcpy(b, a, p - 1);
			memmove(a, a + p - 1, c);
			memcpy(a + c, b, p - 1);
		}
		printf("%d\n", (int)a[0]);
	}
}

C++: #include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int main(void)
{
  while(true) {
    int n, r;
    cin >> n >> r;
    if(n == 0 && r == 0) break;
    vector<int> card;
    REP(i, n) card.push_back(i+1);
    REP(i, r) {
      int p, c;
      cin >> p >> c;
      vector<int> temp;
      REP(i, c) temp.push_back(card[n-c-p+i+1]);
      card.erase(card.begin()+n-c-p+1, card.begin()+n-p+1);
      REP(i, c) card.push_back(temp[i]);
    }

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

  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)
#define COUNTER int i= 0,j = 0,k = 0,l = 0,m = 0, n= 0;
#define RETURN cout << endl;

using namespace std;

int main (void){
    
    COUNTER
    int number;
    int r;
    
    while(cin >> number >> r ,number+r)
    {
        int p,c;
        
        vector<int>d(51,0);
        for(int i = 0; i<= number;i++){d[i] = number-i;}
        for(int i = 0; i< r;i++)
        {
            cin >> p >> c;
            vector<int>temp(51,0);
            for(int i = p-1; i< p-1+c;i++)
            {
                temp[i] = d[i];
               // cout << temp[i] << endl;
            }
            for(int l = 0; l < c;l++)
            {
                //cout << d[p-1];
                d.erase(d.begin()+p-1);
                
            }
            d.insert(d.begin(),temp.begin()+p-1,temp.begin()+c+p-1);
            /*REP(i,number)
            cout << d[i] << " ";*/
        }
        cout << d[0] << endl;
        
    }

    return 0;
}