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 <stack>
#include <queue>
using namespace std;

int n;
int r;
int p;
int c;

int main() {
  while (1) {
    scanf("%d%d", &n, &r);
    if (n == 0 && r == 0) return 0;

    stack<int> st;
    for (int i=1; i<=n; i++) {
      st.push(i);
    }

    while (r--) {
      stack<int> st2, st3;

      scanf("%d%d", &p, &c);
      for (int i=0; i<p-1; i++) {
        int t = st.top(); st.pop();
        st2.push(t);
      }

      for (int i=0; i<c; i++) {
        int t = st.top(); st.pop();
        st3.push(t);
      }

      while (!st2.empty()) {
        int t = st2.top(); st2.pop();
        st.push(t);
      }

      while (!st3.empty()) {
        int t = st3.top(); st3.pop();
        st.push(t);
      }
    }

    printf("%d\n", st.top());
  }
}

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

using namespace std;

int main()
{
	int n, r, p, c, cd[55];
	while(cin >>n >>r, n!=0 || r!=0){
		iota(cd,cd+55,1);
		while(r--){
			cin >> p>>c;
			rotate(cd+(n-p-c+1),cd+(n-p+1),cd+n);
			//rep(i,n) printf("%d ",cd[i]); puts("");
		}
		cout << cd[n-1] <<endl;
	}

}

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 && !m)break;
    queue<int> que,p,q,r;
    int a,b;
    lep(i,1,n)que.push(n-i+1);
    rep(i,0,m){
      cin >> a >> b;
      rep(i,0,a-1){
        p.push(que.front());
        que.pop();
      }
      rep(i,0,b){
        q.push(que.front());
        que.pop();
      }
      //cout <<"size:" << que.size() << endl;
      while(!que.empty()){
        r.push(que.front());
        que.pop();
      }
      while(!q.empty()){
        que.push(q.front());
        q.pop();
      }
      while(!p.empty()){
        que.push(p.front());
        p.pop();
      }
      while(!r.empty()){
        que.push(r.front());
        r.pop();
      }
    }
    print(que.front());
  }
  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;



int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	while (1) {
		ll n, r; scanf("%lld %lld", &n, &r);
		if (n == 0 && r == 0) break;
		deque<ll> q;
		stack<ll> s1,s2;
		for (ll i = n; i >= 1; i--) q.push_back(i);
		for (ll i = 0; i < r; i++) {
			ll p, c; scanf("%lld %lld", &p, &c);
			p--;
			for (ll j = 0; j < p; j++) {
				s1.push(q.front());
				q.pop_front();
			}
			for (ll j = 0; j < c; j++) {
				s2.push(q.front());
				q.pop_front();
			}
			while (!s1.empty()) {
				q.push_front(s1.top());
				s1.pop();
			}
			while (!s2.empty()) {
				q.push_front(s2.top());
				s2.pop();
			}
		}
		printf("%lld\n", q.front());
	}
	return 0;
}

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

int main(){
  int n,r;
  cin >> n >> r;
  vector<int> ans;
  while(n||r){
    vector<int> card(n);
    for(int i = 0; i < r; i++){
      card[i] = n - i;
    }
    for(int i = 0; i < r; i++){
      int p,c;
      cin >> p >> c;
      int start = p - 1;
      int end = p + c -2;
      vector<int> sub(c);
      for(int j = 0; j < c;j++){
        sub[i] = card[start+i];
      }
      for(int j = 0; j < c; j++){
        card[end-j] = card[start-j];
      }
      for(int j = start - 1; j > c - 1;j++){
        card[j] = card[j-c];//
      }
      for(int j = 0; j < c; j++){
        card[j] = sub[j];
      }
    }
    ans.push_back(card[0]);
    cin >> n >> r;
  }
  for(int i = 0; i < ans.size(); i++){
    cout << ans[i] << endl;
  }
}

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

using namespace std;

int main(){
  int n,r;

  while(cin>>n>>r,n){
    int p,c;
    vector<int> cards;
    
    for(int i=n;i>0;--i){
      cards.push_back(i);
    }
    
    for(int i=0;i<r;++i){
      cin>>p>>c;
      vector<int> temp;
      for(int j=0;j<c;++j){
	temp.push_back(cards[p-1]);
	cards.erase(cards.begin()+p-1);
      }
      
      int j=0;
      for(auto i:temp){
	cards.insert(cards.begin()+j,i);
	j++;
      }
    }
    cout<<cards[0]<<endl;
  }
}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,R;
    cin >> N >> R;
    while(N){
        vector<int> V(N);
        iota(V.rbegin(), V.rend(), 1);
        for(auto i:V)cout << i << endl;
        rep(i,0,R){
            int p,c;
            cin >> p >> c;
            vector<int> tmp(p + c - 1);
            rep(j,0,c){
                tmp[j] = V[j + p - 1];
            }
            rep(j,c,p+c-1){
                tmp[j] = V[j-c];
            }
            rep(j,0,p+c-1){
                V[j] = tmp[j];
            }
        }
        cout << V[0] << endl;
        cin >> N >> R;
    }
}

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


using namespace std;
int main()
{
    int n,r;
    while(cin>>n>>r){
        
        if(n==0&&r==0)break;
        stack<int> st1;
        for(int i=0; i<n; i++){
            st1.push(i+1);
        }
        
        for(int rop=0; rop<r; rop++){
            int p,c;
            cin>>p>>c;
            stack<int> st2,st3;
            for(int i=0; i<p-1; i++){
                st2.push(st1.top());
                st1.pop();
            }
            
            for(int i=0; i<c; i++){
                st3.push(st1.top());
                st1.pop();
            }
            
            while (!st2.empty()) {
                st1.push(st2.top());
                st2.pop();
            }
            
            while (!st3.empty()) {
                st1.push(st3.top());
                st3.pop();
            }
        }
        
        cout<<st1.top()<<endl;
    }
}