Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		n, _ := strconv.Atoi(chunks[0])
		r, _ := strconv.Atoi(chunks[1])
		cards := make([]int, n, n)
		for i := 0; i < n; i++ {
			cards[i] = n - i
		}
		for i := 0; i < r; i++ {
			sc.Scan()
			chunks := strings.Split(sc.Text(), " ")
			p, _ := strconv.Atoi(chunks[0])
			c, _ := strconv.Atoi(chunks[1])
			block := make([]int, c, c)
			for j := 0; j < c; j++ {
				block[j] = cards[p+j-1]
			}
			for j := p - 2; j >= 0; j-- {
				cards[j+c] = cards[j]
			}
			for j := 0; j < c; j++ {
				cards[j] = block[j]
			}
		}
		fmt.Println(cards[0])
	}
}

C++: #include <bits/stdc++.h>
#include <iterator>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(v) begin(v), end(v)
#define rreps(i, a, n) for (ll i = (a); i <= (ll)(n); ++i)
#define rrep(i, n) rreps(i, 0, n)
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define each(i, n) for (auto&& i : n)
#define fill(x, y) memset(x,y,sizeof(x))
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <typename T> inline void print(const T& x) {cout << x << '\n';}

signed main()
{ 
  int n,r;
  vi ans;
  while(cin>>n>>r, n||r)
  {
    vi card(n);
    rep(i,n) card[i]=n-i-1;
    rep(k,r)
    {
      int p,c; cin>>p>>c;
      p--; c--;
      for(int j=p; j<p+c+1;j++)
      {
        for(int i=j; i>j-p; i--)
        {
          swap(card[i],card[i-1]);
        }
      }
    }
    ans.push_back(card[0]);
  }
  each(v,ans) print(v+1);
  return 0;
}

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

using namespace std;
int n, r, p, c;

int main(){
	while (cin >> n >> r && n){
		int a[55] = {};
		for (int i = 0; i < n; i++){
			a[i] = i + 1;
		}
		for (int j = 0; j < r; j++){
			cin >> p >> c;
			rotate(a + n - p - c + 1, a + n - p + 1, a + n);
		}
		cout << a[n - 1] << endl;
	}
	return 0;
}

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

int main() {
    int n, r;
    while (cin >> n >> r, n) {
        vector<int> cards(n);
        for (int i = 0; i < n; i++) cards[i] = n - i;
        while (r--) {
            int p, c; cin >> p >> c; p--;
            vector<int> blue(cards.begin(), cards.begin() + p);
            vector<int> yellow(cards.begin() + p, cards.begin() + p + c);
            while (p--) cards[p + c] = blue.back(), blue.pop_back();
            while (c--) cards[c] = yellow.back(), yellow.pop_back();
		}
        cout << cards.front() << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
#define M 50

int main(void)
{
	int n,r;
	int p,c;
	int i,j,k,l;
	int a[M],temp[M];
	
	for(;;)
	{
		scanf("%d %d",&n,&r);
		if(n==0 && r==0) break;
		
		for(i=0; i<n; i++)
		{
			a[i]=i+1;
			temp[i]=i+1;
		}
		
		for(j=0; j<r; j++)
		{
			scanf("%d %d", &p, &c);
			for(i=0; i<n; i++)
			{
				temp[i]=a[i];
			}
			for(k=0; k<c; k++)
			{
				a[n-1-k]=a[n-p-k];
				for(l=0; l<c;l++)
				{
					a[n-p-k+l]=temp[n-p-k+1+l];
				}
			}
			
		}
		printf("%d\n",a[n-1]);
	}
	
	
	return 0;
}

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

using namespace std;

int main(){
	int n,r;
	
	while(cin >> n >> r){
		if(!(n|r)) break;
		int pos = 0;
		vector<pair<int,int> > inst(r);
		for(int i=0;i<r;i++){
			cin >> inst[i].first >> inst[i].second;
		}
		
		reverse(inst.begin(), inst.end());
		
		for(int i=0;i<r;i++){
			if(pos < inst[i].second){
				pos += inst[i].first-1;
			}else if(pos < inst[i].first + inst[i].second-1){
				pos -= inst[i].second;
			}
		}
		cout << n - pos << endl;
	}
}

C++: #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
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; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;

    while(true){
        ll n,r;
        cin>>n>>r;
        if(n==0&&r==0) break;
        vll v(n);
        rep(i,n) v[i]=n-i;
        rep(i,r){
            ll p,c;
            cin>>p>>c;
            vll t(p-1),s(c);
            rep(i,p-1) t[i]=v[i];
            rep(i,c) s[i]=v[p-1+i];
            rep(i,c) v[i]=s[i];
            rep(i,p-1) v[c+i]=t[i];
        }
        cout<<v[0]<<endl;
    }

    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
vector <string> v;
vector<int> ans;
string s;
vector<int> yama;
int main(){
  int n,r;
  cin >> n>>r;
  while((n != 0)&&(r != 0)){
    int p,c;

    for(int i = n; i > 0;i--){
      yama.push_back(i);
    }
    for (int  i = 0 ; i< r;i++){
      cin >> p>>c;
      vector<int> cpy(yama.begin()+p,yama.begin()+c-1);
      yama.erase(yama.begin()+p,yama.begin()+c-1);
      copy(yama.begin(),yama.end(),back_inserter(cpy));
    }
    ans.push_back(yama.front());
    cin >> n>>r;
  }

  for (int i = 0 ;i < (int)ans.size(); i++){
    cout << ans[i]<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	int n,r,p,c,t[50],s[50];
	while(true){
		cin >> n >> r;
		if(n==0 && r==0) return 0;
		for(int i=0;i<n;i++)
			t[i]= n-i;
		for(int i=0;i<r;i++){
			cin >> p >> c;
			for(int j=0;j<c;j++)
				s[j]=t[p-1+j];
			for(int j=0;j<p-1;j++)
				s[j+c]=t[j];
			for(int j=p+c-1;j<n;j++)
				s[j]= t[j];
			for(int j=0;j<n;j++)
				t[j]=s[j];

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

}