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 <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
int d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];

int main(){
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0)break;
    int a,b;
    queue<int> que;
    rep(i,0,n)que.push(i+1);
    rep(i,0,m){
      queue<int> p,q;
      cin >> a >> b;
      rep(i,0,a){
        p.push(que.front());
        que.pop();
      }
      rep(i,0,b){
        q.push(que.front());
        que.pop();
      }
      rep(i,0,a){
        que.push(p.front());
        p.pop();
      }
      rep(i,0,b){
        que.push(q.front());
        q.pop();
      }
    }
    print(que.front());
  }
  return 0;
}

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

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long

//constant
const int MOD = 1000000009;
//const int INF = INT_MAX / 3;

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
	int n, r;
	while (cin >> n >> r, n) {
		vi st(n);
		REP(i, n)
			st[i] = n-i ;

		REP(i, r) {
			vi sw(n);
			REP(i, n)
				sw[i] = st[i];
			int p, c;
			cin >> p >> c;
			REP(j, c)
				sw[j] = st[p-1  + j];
			REP(j, p-1)
				sw[j + c] = st[j];


			REP(i, n)
				st[i] = sw[i];

		}

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

	return 0;
}

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 ans[1000];
int n,r,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;
		}
	}
	ans[counter]=n-card[0]+1;
	counter++;
}



int main (){
	counter=0;
	while(input()){
	solve();
	}
	for(int i=0;i<counter;i++){
	cout<<ans[i]<<endl;
	}
return 0;
}

C++: #include <bits/stdc++.h>
const int INF = 1e9;
const int MODk = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    int n,r;
    while(cin >> n >> r){
        if(n == 0 && r == 0)return 0;
        vector<int> cards(n);
        iota(cards.begin(),cards.end(),1);
        for(int i = 0;i < r;i++){
            int p,c;cin >> p >> c;
            vector<int> vec(n);
            for(int a = 0;a <= n-p-c;a++){
             //   cout<<a<<endl;
                vec.at(a) = cards.at(a);
            }
           // cout<<endl;
            for(int a = n-p-c+1 ;a <= n-(p);a++){
            //    cout<<a<<endl;
                vec.at(a+(p-1)) = cards.at(a);

            }
        //    cout<<endl;
            for(int a = n-p+1;a < n;a++){
          //      cout<<a<<endl;
                vec.at(a-c) = cards.at(a);
            }
            cards = vec;
        }
        cout<<cards.back()<<endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;


int n,r;
main(){
	int i,j,p,c;
	while(cin >> n >> r, n){
		int ans;
		int Deck[51];
		for(i=1;i<=n;i++) Deck[i] = i;
		for(j=1;j<=r;j++){
			cin >> p >> c;
			for(i=1;i<=n;i++){
				if(Deck[i] < p) Deck[i] += c;
				else if(Deck[i] < p+c) Deck[i] -= p-1;
			}
		}
		for(i=1;i<=n;i++){
			if(Deck[i] == 1) break;
		}
		cout << n-i+1 << endl;
	}
	return 0;
}

C++: #include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
  int n,r,p,c;
  int i;
  while(cin >> n >> r && n != 0){
    vector<int> A(n);
    for(i=0;i<n;i++) A[i] = n-i;
    for(i=0;i<r;i++){
      cin >> p >> c;
      rotate(A.begin(),A.begin()+p-1,A.begin()+p+c-1);
    }
    cout << A[0] << endl;
  }
  return 0;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int Card[60];
int temp[60];
int main()
{
  int n,r;
  while(cin >>n>>r,n||r){
  int k = n;
  for(int i = 1; i <=n;i++){
    Card[i] =k--;
  }
  int p,c;
  for(int i = 0;i <r;i++){
    cin>>p>>c;
    int l = 1;
    int m = 1;
    for(int j = 1; j <=p+c-1;j++){
      temp[j] = Card[j];
    }for(int j = p;j <=p+c-1;j++){
      Card[l++] =Card[j];
    }for(int j =1 ;j <=p-1;j++){
      Card[l+j-1] =temp[m++];
    }
  }
  cout <<Card[1]<<endl;
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

int main(void){
	
	int yama[50],temp[50],cut,n,p,c;

	while(cin>>n>>cut,n){
		for(int i=0;i<50;i++){
			yama[i]=0;
			temp[i]=0;
		}
		for(int j=0;j<n;j++){
			yama[j]=n-j;
		}
		for(int i=0;i<cut;i++){
			
			cin>>p>>c;
			
			for(int i=0;i<p-1;i++){
				temp[i]=yama[i];
			}
			for(int i=0;i<c;i++){
				yama[i]=yama[(p-1)+i];
			}
			for(int i=0;i<p-1;i++){
				yama[c+i]=temp[i];
			}
		}
		cout<<yama[0]<<endl;
	}
}