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

using namespace std;

int main(void)
{
  while(1){
    int n, r;
    cin >> n >> r;
    if(n == 0 && r == 0)
      break;
    
    int card[n+1];
    for(int i = 1; i <= n; i++) card[i] = n - i + 1;
    // for(int i = 1; i <= n; i++) printf("%d ", card[i]);
    // puts("A");
    
    int shuf[n+1];
    shuf[0] = 0;
    for(int i = 1; i <= r; i++){
      int p, c;
      cin >> p >> c;
      
      for(int j = 0; j < c; j++){ // p~
	shuf[j+1] = card[p+j];
	//	printf("%d ", shuf[j+1]);
      }
      // printf("|");
      for(int j = 1; j < p; j++){ // 1~
	shuf[c+j] = card[j];
	//printf("%d ", shuf[c+j]);
      }
      // printf("|");
      for(int j = c + p; j <= n; j++){ //others
	shuf[j] = card[j];
	//printf("%d ", shuf[j]);
      }
      //puts("");
      for(int j = 1; j <= n; j++){ // copy
	card[j] = shuf[j];
      }
      for(int j = 1; j <= n; j++){
	//	printf("%d ", card[j]);
      }
      //puts("");
      
    }

    printf("%d\n", card[1]);
  }
  
  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (typeof((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(typeof(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



int main() {
    //freopen( "/Users/macuser/Documents/Programming/Contest/input.in", "r", stdin );
    int n, r;
    while (cin >> n >> r) {
        if (n == 0) break;
        
        deque<int> hana(n);
        for (int i = 0; i < n; ++i) hana[i] = n-i;
        for (int i = 0; i < r; ++i) {
            int c, p;
            cin >> p >> c;
            vint temp;
            for (int k = 0; k < c; ++k) {
                temp.PB(hana[p-1]);
                hana.erase(hana.begin()+p-1);
            }
            reverse(ALL(temp));
            for (int k = 0; k < c; ++k) {
                hana.push_front(temp[k]);
            }
            
            //for (int i = 0; i < n; ++i) cout << hana[i] << ","; cout << endl;
        }
    
        cout << hana[0] << endl;
    }
    
    return 0;
}

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

int main(void){
  vector<int> f;
  while(1){
    f.clear();
    int n, r, p, c;
    cin >> n >> r;
    if(n == 0 && r == 0) return 0;
    for(int i=n; i > 0; i--){
      f.push_back(i);
    }


    vector<int> t;
    for(int i=0; i < r; i++){
      cin >> p >> c;
      t.clear();
      for(int j=p-1; j < p+c-1; j++){
        t.push_back(f.at(j));
      }
      for(int j=p-1; j > 0; j--){
        f.at(j+c-1) = f.at(j-1);
      }
      for(int j=0; j < c; j++){
        f.at(j) = t.at(j);
      }


    }
    cout << f.front() << endl;
  }
}

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

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

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

			vector<int> change;

			for(int i=p-1; i<p-1+c; i++){
//				cout << "step1 " << card[i] << endl;
				change.push_back(card[i]);
			}
			for(int i=0; i<p-c; i++){
//				cout << "step2 " << card[i] << endl;
				change.push_back(card[i]);
			}
			
			int count=0;
			vector<int>::iterator it = change.begin();
			while(it!=change.end()){
				card[count] = *it;
				count++;
				it++;
			}
			
		}
		cout << card[0] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS

    while(true) {
        int n, r;
        cin >> n >> r;
        if (n == 0) break;
        vector<int> v(n);
        iota(RALL(v),1);
        REP(i,r) {
            int p, c;
            cin >> p >> c;
            p--;
            vector<int> tmp(v.begin()+p,v.begin()+p+c);
            tmp.insert(tmp.end(),v.begin(),v.begin()+p);
            tmp.insert(tmp.end(),v.begin()+p+c,v.end());
            swap(v,tmp);
        }
        cout << v[0] << endl;
    }

    return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

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

C++: #include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;
int b[50],a[50];
int n,r,p,c;
void sol();
int main(){
	while (1){
		cin >> n >> r;
		if (n==0 && r==0) 	return 0;
		for(int i= 0;i<n;i++){
			b[i] = i+1;
		}

		for(int i=0;i<r;i++){
			cin >> p >> c ;
			sol();
			for(int i= 0;i<n;i++){
			//	cout << b[i] << " " << a[i] <<endl;
				b[i] = a[i];
				
			}				
		}
		cout << a[n-1] << endl;
	}

}

void sol(){
	for(int i= 0;i<n-p-c+1;i++){
		a[i]=b[i];
	}
	for(int i=n-p-c+1;i<n-c;i++){
		a[i]=b[c+i];
	}
	for(int i=n-c;i<n;i++){
		a[i]=b[i-p+1];
	}
}

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

int main(){

    int n,cu; 

    int rea[50],ano[50];

    while(1){

        cin>>n>>cu;

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

        for(int i=0; i<n; i++) rea[i] = n-i;

        for(int i=0; i<cu; i++){

            int p,num; cin>>p>>num;

            for(int j=0; j<n; j++) ano[j] = rea[j];

            for(int j=0; j<p-1; j++) ano[ j + num] = rea[j];

            for(int j=0; j<num; j++) ano[j] = rea[j+p-1];

            for(int j=0; j<n; j++) rea[j] = ano[j];
        }

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

    return 0;
}