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 <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
// int dx[]={0,1,0,-1,1,-1};
// int dy[]={1,0,-1,0,1,-1};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}
void printvi(vector<int> v){rep(i,0,v.size()){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
void printvil(vector<int> v){rep(i,0,v.size()){cout<<v[i]<<endl;}}
void printvvi(vector<vector<int>> v){
    rep(i,0,v.size()){
        rep(j,0,v[i].size())cout<<v[i][j];
        cout<<endl;
    }
}
void printvstr(vector<string> v){
    rep(i,0,v.size()){
        cout<<v[i]<<endl;
    }
}

signed main (){
    int n,r;
    while(1){
        cin>>n>>r;
        if(n+r==0)break;
        vector<int> v(n);
        rep(i,0,n)v[i]=i+1;
        rep(i,0,r){
            int p,c;
            cin>>p>>c;
            vector<int> P,C;
            rep(j,0,p-1){
                P.emplace_back(v.back());
                v.erase(v.end()-1);
            }
            //printvi(P);
            rep(j,0,c){
                C.emplace_back(v.back());
                v.erase(v.end()-1);
            }
            //printvi(C);
            reverse(all(P));
            reverse(all(C));
            rep(j,0,p-1){
                v.emplace_back(P[j]);
            }
            rep(j,0,c){
                v.emplace_back(C[j]);
            }
            //printvi(v);
        }
        cout<<v.back()<<endl;
    }
    
}
/*
FRCFCRF
*/

C++: #include <stdio.h> 
#include <stdlib.h> 

int main(){ 

	int n,r,i,j,p,k,c,a=0; 

	int data[1000],buff[1000],answer[1000]; 

	while(1){ 

 		scanf("%d",&n);
	 	scanf("%d",&r);


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

		for(i=n;i>0;i--){ 
		data[n-i]=i;	
		} 

		for(j=0;j<r;j++){ 

 
 		scanf("%d",&p);
 		scanf("%d",&c);
 

		p--; 
		c=p+c-1;


			for(i=p,k=0;i<=c;i++,k++){ 
			buff[k] = data[i]; 
			} 


		i = 0; 
			while(i < p){ 
			buff[k] = data[i]; 
			k++; 
			i++; 
			} 


		i=c+1; 
			while(i < n){ 
buff[k] = data[i]; 
k++;	
i++; 
} 


for(i=0;i<n;i++){ 
data[i] = buff[i]; 
} 
} 

answer[a] = data[0];
 a++;
} 
 for(i=0;i<a;i++){
 printf("%d\n",answer[i]);
}




return 0; 
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n,r;
  while(true){
    cin >> n >> r;
    if(n==0) break;
    int p,c;
    int now[n+1],pre[n+1];
    for(int i=1;i<=n;i++) pre[i]=n-i+1;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      for(int j=1;j<=c;j++) now[j]=pre[j+p-1];
      for(int j=c+1;j<=p+c-1;j++) now[j]=pre[j-c];
      for(int j=p+c;j<=n;j++) now[j]=pre[j];
      for(int j=1;j<=n;j++) pre[j]=now[j];
    }
    cout << now[1] << endl;
  }
}

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

int main(){
  int n,r;
  while(cin >> n >> r, n){
    int npos[100];
    for(int i=n-1,j=0;i>=0;i--,j++){
      npos[j] = i+1;
    }
    for(int i=0;i<n;i++){
      cout << npos[i] << endl;
    }
    for(int i=0;i<r;i++){
      int a,b;
      cin >> a >> b;
      int tmp[b];
      for(int j=0;j<b;j++){
	tmp[j] = npos[j+a-1];
      }
      for(int j=a+b-2;j>=b;j--){
	npos[j] = npos[j-b];
      }
      for(int j=0;j<b;j++){
	npos[j] = tmp[j];
      }
      for(int i=0;i<n;i++){
	cout << npos[i] << endl;
      }
    }
    cout << npos[0] << endl;
  }
}

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

int main(void){
	int n,r,c,p,a;
	while(1){
		cin >> n >> r;
		if(!n && !r) break;
		vector<int> d(n);
		for(int i=0;i<n;i++){
			d[i] = n-i;
		}
		for(int i=0;i<r;i++){
			cin >> p >> c;
			for(int j=c; j>0;j--){
				a = d[c+p-2];
				d.erase(d.begin()+c+p-2);
				d.insert(d.begin(),a);


			}
			// for(int j=0;j<n;j++){
			// cout << d[j] << endl;
			// }
		}
		// cout << "answer" << endl;
		// for(int i=0;i<n;i++){
		// 	cout << d[i] << endl;
		// }
		cout << d[0] << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;main(){for(int n,r,p,c;cin>>n>>r,n;){string d;for(int i=0;i<n;i++)d=char(48+i)+d;for(;r;r--){cin>>p>>c;d = d.substr(p-1,c)+d.substr(0,p-1)+d.substr(p+c-1);}cout<<(d[0]-47)<<"\n";}}