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>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

void hanafuda_shuffle(int p,int c,vi &A){
    vi a,b;
    rep(i,p-1){
        a.eb(A[i]);
    }
    rep(i,c){
        b.eb(A[i+p-1]);
    }
    rep(i,c){
        A[i]=b[i];
    }
    rep(i,p-1){
        A[i+c]=a[i];
    }
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    while(true){
        int n,r; cin >> n >> r;
        if(n==0 && r==0) break;
        vi A(n);
        rep(i,n) A[i]=n-i;
        rep(j,r){
            int s,t; cin >> s >> t;
            hanafuda_shuffle(s,t,A);
        }
        cout << A[0] << endl;
    }
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
using namespace std;
int x[100];
int y[100];
int card [100];
int n,r;
int ans[1000];
int counter;
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;
}
    }
  
    ans[counter]=card[0];
 counter+=1;
}
   
   
   
int main (){
counter=0;
    while(input()){
    solve();
    }
for(int j=0;j<=counter;j++){
cout<<ans[counter]<<endl;
}
return 0;
}

C++: #include <cctype>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#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 INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

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

int main(){
	int n, r;

	while(cin >> n >> r, n + r){
		int huda[51];
		REP(i, n){
			huda[i] = n - i;
		}
		
		while(r--){
			int p, c;
			int tmp[51];
			cin >> p >> c;
			
			REP(i, c){
				tmp[i] = huda[p + i - 1];
			}
			
			REPR(i, p - 2){
				huda[i + c] = huda[i];
			}

			REP(i, c){
				huda[i] = tmp[i];
			}
		}

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

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 <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it = (c).begin(); it != (c).end(); it++)
#define X first
#define Y second

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
    for(int n, r; cin >> n >> r, n;){
        string y;
        rep(i, n) y.pb('0' + n - i);

        while(r--){
            int p, c; cin >> p >> c;

            string str1 = y.substr(p - 1, c);
            string str2 = y.substr(0, p - 1);
            string str3 = y.substr(p + c - 1);
            y = str1 + str2 + str3;
        }

        cout << (int)(y.at(0) - '0') << endl;
    }

    return 0;
}

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

using namespace std;

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

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

    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;
}

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

using namespace std;

int cards[50];
int n, r;

void cut(int p, int c) {
	vector<int> temp(c);
	for (int i = 0; i < c; i++) {
		temp[i] = cards[p + i - 1];
	}

	for (int i = p - 2; i >= 0; i--) {
		cards[i + c] = cards[i];
	}

	for (int i = 0; i < c; i++) {
		cards[i] = temp[i];
	}
}

int main() {
	while (true) {
		cin >> n >> r;
		if (!n && !r) break;

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

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

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

	return 0;
}