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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int main()
{
    int n, r, p[64], c[64];
    while (scanf("%d%d", &n, &r), n | r)
    {
	for (int i = 0; i < r; ++i)
	    scanf("%d%d", p + i, c + i);

	int pos = 0;
	for (int i = r - 1; i >= 0; --i)
	{
	    if (pos < c[i])
		pos += p[i] - 1;
	    else if (pos < c[i] + p[i])
		pos -= c[i];
	}
	printf("%d\n", n - pos);
    }
}

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

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
	int n, r;
	while(cin >> n >> r, n+r){
		int card[n];
		rep(i, n) card[i] = n-i;
		int p, c;
		for(int i=0; i< r; i++){
			cin >> p >> c;

			int a[55], b[55];
			rep(i, p) a[i] = card[i];
			rep(i, c) b[i] = card[p+i-1];
			rep(i, c) card[i] = b[i];
			rep(i, p) card[i+c] = a[i];
		}
		cout << card[0] << endl;
	}
}

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

#define first  fs
#define second se
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, char s = '\n') { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	int n, r;
	while (cin >> n >> r, n) {
		vi v;
		rep(i, n) v.push_back(n - i);

		rep(_, r) {
			int p = in(), c = in();
			vi beet, ei;
			for (int i = p - 1; i < p + c - 1; ++i) beet.push_back(v[i]);
			rep(i, p - 1) beet.push_back(v[i]);

			rep(i, p + c) v[i] = beet[i];
		}

		print(v[0]);
	}
}

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

void show(vector<int> a){
  for(int i=0;i<a.size();i++){
    cout << a[i] << endl;
  }
  cout << endl;
}
int main(){
  while(1){
    int N,R;
    cin >> N >> R;
    if(N==0&&R==0)break;
    vector<int> a;
    for(int i=N;i>=1;i--){
      a.push_back(i);
    }
    for(int i=0;i<R;i++){
      int p,c;
      cin >> p >> c ;
      vector<int> b;
      for(int j=0;j<c;j++){
        b.push_back(a[p-1+j]);
      }
      a.erase(a.begin()+p,a.begin()+p-1+c);
      a.insert(a.begin(),b.begin(),b.end());
    }
    cout << a[0] << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int x[100];
int y[100];
int card [100];
int n,r;
bool input(){
    for(int i=0;i<100;i++){
    x[i]=0;
    y[i]=0;
    }
    cin >>n>>r;
    for(int i=0;i<r;i++){
    cin>>x[i]>>y[i];
    }
    if(n==0){
    return false;
    }
    else{
     return true;
    }
}
void solve(){
    for(int i=0;i<100;i++){
        card[i]=i+1;
    }
    for(int i=0;i<r;i++){
        for(int k=0;k<y[i];k++){
            int a=card[x[i]+y[i]-2];
            for(int j=x[i]+y[i]-1;j>0;j--){
                card[j]=card[j-1];
            }
            card[0]=a;
           
        }
    for(int j=1;j<=y[i]/2;j++){
int remainder=card[j];
card[j]=card[y[i]-j];
card[y[i]-j]=remainder;
}
    }

    cout<<n-card[0]+1<<endl;
}
 
 
 
int main (){
    while(input()){
    solve();
    }
return 0;
}

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

int main()
{
	int n = 0;
	int r = 0;
	int p = 0;
	int c = 0;

	int deck[50] = {};
	int tmp[50] = {};

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

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

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

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


			for (int j = 0; j < p - 1; j++)
			{
				deck[c + j] = tmp[j];
			}
		}
		cout << deck[0] << endl;
	}
	return 0;
}

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

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

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( unsigned int i = (unsigned int)( m ); i < (unsigned int)( n ); i++ )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define RALL( c ) (c).rbegin(), (c).rend()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

VI shuffle( VI vec, int p, int c )
{
	VI res( vec.begin() + p, vec.begin() + p + c );
	vec.erase( vec.begin() + p, vec.begin() + p + c );
	res.insert( res.end(), ALL( vec ) );
	
	return res;
}

int main()
{	
	while ( true )
	{
		int n, r;
		cin >> n >> r;

		if ( !( n | r ) )
		{
			break;
		}

		VI res( n );
		REP( i, 0, n )
		{
			res[i] = n - i;
		}

		REP( i, 0, r )
		{
			int p, c;
			cin >> p >> c;

			res = shuffle( res, p - 1, c );
		}

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

	return 0;
}