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 <cstdio>
#include <cstring>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
int n,r;
int f[55],cp[55];
int main(void){
	for(;;){
		scanf("%d%d",&n,&r);
		if(n==0)break;
		rep(i,0,n)f[i]=n-i;
		rep(i,0,n)printf("%d ",f[i]);
			printf("\n");
		rep(i,0,r){
			int a,b;
			scanf("%d%d",&a,&b);
			memcpy(cp,f,(a-1)*4);
			memcpy(f,f+a-1,b*4);
			memcpy(f+b,cp,(a-1)*4);
		}
		printf("%d\n",f[0]);
	}
	return 0;
}

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

using namespace std;
int main(){
    while(1){
        int n,r;
        cin >> n >> r;
        if(n==0){
            break;
        }
        vector<int> vec(n,0);
        vector<int> vec1(n,0);
        for(int i=0;i<n;i++){
            vec[i]=n-i;
            vec1[i]=vec[i];
        }
        for(int i=0;i<r;i++){
            int p,c;
            cin >> p >> c;
            p--;
            for(int j=0;j<c;j++){
                vec1[j]=vec[j+p];
            }
            for(int j=c;j<p+c;j++){
                vec1[j]=vec[j-c];
            }
            for(int j=0;j<n;j++){
                vec[j]=vec1[j];
               // cout<< vec[j]<<endl;
            }
          //  cout<<endl;
        }
        cout<< vec[0]<<endl;
        //cout<<endl<<endl;
    }
}

C++: #include <stdio.h>

int main(void){
	int n, r, card[50], i, j, k, tmp, p, c;
	scanf("%d%d",&n,&r);
	while(n != 0 || r != 0){
		for(i = 0;i < n;i++)
			card[i] = n - i;
		for(k = 0;k < r;k++){
			scanf("%d%d",&p,&c);
			for(i = 0;i < c;i++){
				tmp = card[p - 1 + i];
				for(j = p - 1 + i;j > i;j--)
					card[j] = card[j - 1];
				card[i] = tmp;
			}
		}
		printf("%d\n",card[0]);
		scanf("%d%d",&n,&r);
	}
	return 0;
}

C++: #include<cstdio>
using namespace std;
int num1[50],num2[50];
void sets(int N);
void change(int p,int c);
int main()
{
    int N,r,i,j,p,c;
    for(;scanf("%d%d",&N,&r),N+r!=0;)
    {
        sets(N);
        for(i=0;i<r;i++)
        {
            scanf("%d%d",&p,&c);
            change(p,c);
        }
        printf("%d\n",num1[0]);
    }
    return 0;
}
void sets(int N)
{
    for(int i=0,j=N;i<N;i++,j--)
    {
        num1[i]=j;
    }
}
void change(int p,int c)
{
    int i;
    for(i=0;i<p-1;i++)num2[c+i]=num1[i];
    for(i=0;i<c;i++)num2[i]=num1[p-1+i];
    for(int i=0;i<c+p-1;i++) num1[i] = num2[i];
}

C++: #include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int N, R;
  while (cin>>N>>R, N+R!=0) {
    vector<int> x;
    for (int i = 0; i < N; i++) x.push_back(i+1);
    for (int i = 0; i < R; i++) {
      int p, c; cin>>p>>c;
      p = N-p-c+1;
      for (int j = 0; j < c; j++) {
        x.push_back(x[p]);
        x.erase(x.begin()+p);
      }
    }
    cout << x.back() << endl;
  }
}

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

int main() {
	while(true){
		int n,r;
		cin>>n>>r;
		if(n==0&&r==0) return 0;
		vector<int>v(n+5);
		for(int i=0;i<n;i++) v[i]=n-i;
		for(int i=0;i<r;i++){
			int p,c;
			cin>>p>>c;
			vector<int>u(p-1);
			vector<int>l(c);
			for(int i=0;i<p-1;i++) u[i]=v[i];
			for(int i=p-1;i<p-1+c;i++) l[i-(p-1)]=v[i];
			for(int i=0;i<c;i++) v[i]=l[i];
			for(int i=c;i<c+p-1;i++) v[i]=u[i-c];
		}
		cout<<v[0]<<endl;
	}
	return 0;
}

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

int main(){
    int n,r;
    for(int i = 0;;i++){
        scanf("%d%d",&n,&r);
        if(n == 0 && r == 0){
            break;
        }
        int hanafuda[n];
        for(int j = 0;j < n;j++){
            hanafuda[j] = j + 1;
        }
        for(int j = 0;j < r;j++){
            int p,c;
            scanf("%d%d",&p,&c);
            if(c == n){
                continue;
            }
            for(int k = 0;k < c;k++){
                for(int K = 0;;K++){
                    if(p - k + K == n){
                        break;
                    }
                    std::swap(hanafuda[p - k + K - 1],hanafuda[p - k + K]);
                }
            }
        }
        printf("%d\n",hanafuda[n - 1]);
    }
}

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