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 <algorithm>
#include <vector>

#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define REP(i,k,n) for(int i = k; i < n; i++)

#define vi vector<int>
#define pb push_back
using namespace std;

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

        rep(i,n) card[i] = n - i;
        rep(i,r){
            int p,c;
            cin >> p >> c;
            vi tmp(c);
            rep(j,c) tmp[c] = card[p - 1 + j];
            rrep(j,p - 1) card[j + c - 1] = card[j];
            rep(j,c) card[j] = tmp[c];
        }
        cout << card[0] << endl;
    }
    return 0;

}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mp make_pair

void solve(int N, vector<pii> &A) {
    vector<int> hana(N);
    for(int i = 0; i < N; i++) {
        hana[i] = N - i - 1;
    }
    for(int i = 0; i < A.size(); i++) {
        int p = A[i].first;
        int c = A[i].second;
        vector<int> newhana(N);
        for(int j = p; j < p + c; j++) {
            newhana[j - p] = hana[j];
        }
        for(int j = 0; j < p; j++) {
            newhana[c + j] = hana[j];
        }
        for(int j = 0; j < p + c; j++) {
            hana[j] = newhana[j];
        }
    }
    cout << hana[0] + 1 << endl;
}

int main() {
    int N, R;
    while(cin >> N >> R, R) {
        vector<pii> A(R);
        for(int i = 0; i < R; i++) {
            int p, c;
            cin >> p >> c;
            p -= 1;
            A[i] = mp(p, c);
        }
        solve(N, A);
    }
    return 0;
}

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

int N,R;
int D[2][55];
int main(){
  while( cin >> N >> R  && ( N|| R) ){
    for(int i=0;i<N;i++) D[0][i] = i+1;
    for(int i=0;i<R;i++){
      int P,C;
      cin >> P >> C;
      int in = N - (P-1) - C;
      for(int j=0;j<C;j++){
	D[1][in+(P-1)+j] = D[0][in+j];
      }
      for(int j=0;j<P-1;j++){
	D[1][in+j] = D[0][in+C+j];
      }
      for(int j=0;j<N;j++) D[0][j] = D[1][j];
    }
    cout << D[0][N-1] << endl;
  }
}

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

int main(){
    while(1){
        int n,r;
        cin >> n >> r;
        if(n==0) break;
        
        vector<int> deck(n);
        for(int i=0; i<n; i++){
            deck[i] = n-i;
        }
        
        for(int i=0; i<r; i++){
            int p,c;
            cin >> p >> c;
            vector<int> tmp(c);
            for(int j=0; j<c; j++){
                tmp[j] = deck[p+j-1];
            }
            for(int j=p-2; j>=0; j--){
                deck[j+c] = deck[j];
            }
            for(int j=0; j<c; j++){
                deck[j] = tmp[j];
            }
        }
        cout << deck[0] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    while(1){
        int n,r,i,p,c;
        cin>>n>>r;
        if(n==0) break;
        valarray<int> deck(n);
        for(i=0;i<n;i++){
            deck[i]=n-i;
        }
        for(i=0;i<r;i++){
            int j;
            cin>>p>>c;
            valarray<int> top = deck[slice(0,p-1,1)];
            valarray<int> mid = deck[slice(p-1,c,1)];
            for(j=0;j<mid.size();j++){
                deck[j]=mid[j];
            }
            for(;j<mid.size()+top.size();j++){
                deck[j]=top[j-mid.size()];
            }
        }
        cout<<deck[0]<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#define N 50
using namespace std;

int main(){

  int n,r,ans;
  int operate[N][2];

  while(true)
    {
      cin >> n >> r;
      if(n == 0 && r == 0)break;

      for(int i=0;i<r;i++)cin >> operate[i][0] >> operate[i][1];
      ans = n;
      int da = n;
     
      for(int i=r-1;i>=0;i--){
	da = n;
	if(n-operate[i][1] <= ans && ans <= n)
	  {
	    if(n == operate[i][1])continue;
	    ans = ans-operate[i][0]+1;
	  
	  }
	else{
	  da = da-operate[i][0]+1;
	  if(da <= ans)ans+=operate[i][1];
	  //else if(da > ans)ans-=operate[i][1];

	}
	//cout << "da ~ " << da << endl;
	//cout << "ans = " << ans << endl;

      }

      cout << ans << endl;



    }

}

C++: #pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 1000000000
#define INF 9223372036854775807
#define MOD 998244353
#define mod 998244353
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll> a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi>b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //-------------------------------
    int n,r;cin>>n>>r;
    while(n&&r){
        int a[51];
        for(int i=0;i<n;i++)a[i]=n-i;
        for(int i=0;i<r;i++){
            int p,c;cin>>p>>c;
            p--;
            ll l=p,r=p+c-1;
            V<ll>move;
            for(ll j=l;j<=r;j++){
                move.pb(a[j]);
                //cout<<a[j]<<endl;
            }
            for(ll j=l-1;j>=0;j--){
                a[j+c]=a[j];
            }
            for(ll j=0;j<c;j++){
                a[j]=move[j];
            }
        }
        cout<<a[0]<<endl;
        cin>>n>>r;
    }
    //-------------------------------  
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------