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 <algorithm>
#include <vector>
#include <cstring>
using namespace std;
int main(){
	int n,r;
	while(cin>>n>>r,n,r){
		int data[50],tmp[50];
		for(int i=0;i<n;i++){
			data[i]=n-i;
			tmp[i]=n-i;
		}
		for(int i=0;i<r;i++){
			int p,c;
			cin>>p>>c;
			for(int j=0;j<p+c-1;j++){
				if(j<p-1){
					tmp[j+c]=data[j];
				}else{
					tmp[j-p+1]=data[j];
				}
			}
			for(int j=0;j<n;j++){
				data[j]=tmp[j];
			}
		}
		cout<<data[0]<<endl;
	}
}

C++: #include <stdio.h>
int main(){
  int n,r,p,c,i,j,k,l,nh[51],s[51];
  while(1){
    scanf("%d%d",&n,&r);
    if(n==0&&r==0) break;
 
    for(i=n;i>=1;i--){
      nh[n-i+1]=i;
    }
  
    for(i=0;i<r;i++){
      scanf("%d%d",&p,&c);
      for(j=p;j<=p+c-1;j++){
        s[j]=nh[j];
      }
    l=0;
      for(j=1;j<=c;j++){
    for(k=p-1+l;k>=1+l;k--){
          nh[k+1]=nh[k];
    }
        l++;
      }
     
      for(j=p;j<=p+c-1;j++){
        nh[j-p+1]=s[j];
      }
    }
 
    printf("%d\n",nh[1]);
  }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int a[51],b[51];
int main(){
    int n,r,p,c;
    while(cin>>n>>r,n){
        rep(i,n) a[i]=n-i;
        rep(i,r){
            cin>>p>>c;
            FOR(j,p-1,p+c-1) b[j-p+1]=a[j];
            for(int j=p-2;j>=0;--j) a[j+c]=a[j];
            rep(j,c) a[j]=b[j];
        }
        cout<<a[0]<<endl;
    }
    return 0;
}

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

int main(){
    int n, r;
    while(cin >> n >> r, n != 0){
        vector<int> deck;
        for(int i=1;i<=n;++i)deck.push_back(i);
        for(int i=0;i<r;++i){
            int p, c;
            cin >> p >> c;
            for(int i=0;i<c;++i){
                deck.push_back(deck[n-(p-1+c)+i]);
            }
            deck.erase(deck.begin() + n-(p-1+c), deck.begin() + n-(p-1));
        }
        cout << deck.back() << endl;
    }

    return 0;
}

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

void shafle(int b, int e, int *ans)
{
    int tmp[50];
    b--;
    for (int i = 0; i < b; i++)
        tmp[i] = ans[i];
    for (int i = b; i < b + e; i++)
        ans[i - b] = ans[i];
    for (int i = e; i < b+e; i++)
        ans[i] = tmp[i - e];
}
int main()
{
    int n, r;
    while (cin >> n >> r, n)
    {
        int ans[50];
        for (int i = 0; i < n; i++)
            ans[i] = n - i;
        for (int i =0 ; i < r; i++) {
            int b, e;
            cin >> b >> e;
            shafle(b, e, ans);
        }
        cout << ans[0] << endl;
    }
    return 0;
}

C++: #include <stdio.h>
int main(){
    int n,r,card[100],p,c,temp[100];
    while(1){
        scanf("%d%d",&n,&r);
        if(n==0&&r==0)return 0;
        for(int i=1;i<=n;i++)card[i]=n-i+1;
        while(r--){
            scanf("%d%d",&p,&c);
            for(int i=1;i<=c;i++)temp[i]=card[i+p-1];
            for(int i=c+1;i<p+c;i++)temp[i]=card[i-c];
            for(int i=1;i<p+c;i++)card[i]=temp[i];
        }
        printf("%d\n",card[1]);
    }
}

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

using ll = long long;
#define int long long

// [a -> b-1]
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
// [0 -> a-1]
#define rep(i, a) reps(i, 0, (a))
// [a-1 -> b]
#define rreps(i, a, b) for (int i = (int)((a)-1); i >= (int)(b); i--)
// [a-1 -> 0]
#define rrep(i, a) rreps(i, a, 0)
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
 * (v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)\
	sort(all(v));\
	(v).erase(unique(all(v)), v.end())
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(15)
#define YES(f) cout << ((f) ? YES_STR : NO_STR) << endl;

using namespace std;

int solve(int n, int r) {
	vector<int> res(n);
	iota(res.rbegin(), res.rend(), 1);
	rep(i, r) {
		int p, c; cin >> p >> c;
		vector<int> t;
		t.insert(t.end(), res.begin() + p - 1, res.begin() + p + c - 1);
		t.insert(t.end(), res.begin(), res.begin() + p - 1);
		t.insert(t.end(), res.begin() + p + c - 1, res.end());
		res = t;
	}
	return res[0];
}

signed main() {
	int n, r;
	while (cin >> n >> r, n) cout << solve(n, r) << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;} return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;} return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,r;
    while(cin >> n >> r,n,r){
        vector<int> cs(n),cs0(n);
        iota(cs.begin(),cs.end(),1);
        reverse(cs.begin(),cs.end());
        rep(i,r){
            int p,c; cin >> p >> c;
            rep(i,n) cs0[i]=cs[i];
            rep(j,p-1) cs[j+c]=cs0[j];
            rep(j,c) cs[j]=cs0[j+p-1];
        }
        cout << cs[0] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main()
{
	int n, m;
	cin >> n >> m;
	if (n == 0 && m == 0) {
		return 0;
	} else {
		string in;
		REP(i, n) in = (char)(i)+in;
		REP(i, m)
		{
			int a, b;
			cin >> a >> b;
			in = in.substr(a - 1, b) + in.substr(0, a - 1) + in.substr(a + b - 1);
		}
		cout << int(in[0] + 1) << endl;
	}
}