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
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const int INF = 10000;

struct edge{int to,cost;};
typedef pair<int,int> P;//firstは最短距離,secondは頂点番号

int main(){
	int n,r;
	
	while(cin>>n>>r){
		if(n==0&&r==0)break;
		int tmp[50],tmp2[50];
		REP(i,n)tmp[i]=n-i;
		
		REP(i,r){
			int p,c;
			cin>>p>>c;
			p--;
			int cnt=0;
			FOR(j,p,p+c){
				tmp2[cnt]=tmp[j];
				cnt++;
			}
			REP(j,n)if(j<p||j>=p+c){
				tmp2[cnt]=tmp[j];
				cnt++;
			}
			REP(j,n)tmp[j]=tmp2[j];
		}
		cout<<tmp[0]<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<string,string> P;
const int INF=1e9+1;
int dat[50];
int n;
void rec(int p,int c){
      int tmp[50];
      REP(i,n)tmp[i]=dat[i];
      for(int i=0;i<c;i++)tmp[i]=dat[i+p-1];
      for(int i=c;i<c+p-1;i++)tmp[i]=dat[i-c];
      REP(i,n)dat[i]=tmp[i];
}
int main(){
      int r;
      while(cin>>n>>r&&(n||r)){
            REP(i,n)dat[i]=n-i;
            REP(i,r){
                  int a,b;
                  cin>>a>>b;
                  rec(a,b);
            }
            cout<<dat[0]<<endl;
      }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int input(char s[]);

int main() {
	int n, r, brk = 0, p, c, x[50], xs[50];
	
	while (1) {
		for (int i = 0; i < 50; i++)
			x[i] = xs[i] = i;
		scanf("%d %d", &n, &r);
		if (n == 0 && r == 0)
			break;
		for (int i = 0; i < r&&brk == 0; i++) {
			scanf("%d %d", &p, &c);
			for (int j = 0; j < c; j++)
				x[j] = xs[j + p - 1];
			for (int j = c; j < c + p - 1; j++)
				x[j] = xs[j - c];
			for (int j = 0; j < n; j++)
				xs[j] = x[j];
			/*for (int j = n-1; j >=0; j--) {
				printf("%2d  %2d\n",j, x[j]);
			}*/
		}
		printf("%d\n", n - x[0]);
	}
	return 0;
}

C++: #include <iostream>
#include <list>
#include <cstdlib>

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	int n,r;

	cin >> n;
	cin >> r;

	while (n != 0 || r != 0) {
		std::list<int> lst;
		int now = 1;

		for (int i = 0; i < n; i++) {
			lst.push_back(i+1);
		}

		for (int i = 0; i < r; i++) {
			int index = 1;
			int p,c;
			cin >> p;
			cin >> c;

			for (std::list<int>::iterator itr = lst.begin(); itr != lst.end();) {
				if (index >  n-(p-1)-c && index < n-(p-2) && r != n){
					lst.push_back(*itr);
					itr = lst.erase(itr);
				}else{
					itr++;
				}	
				index++;
			}
		}
		for (std::list<int>::iterator itr = lst.begin(); itr != lst.end(); ++itr) {
			if (now == n) {
				cout << *itr << endl;
			}
			now++;
		}
		cin >> n;
		cin >> r;
	}	
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
  
int main()
{

	int sum=0;
	int n,m;
	int p[51]={0};
	int c[51]={0};
	int i;
	int ans;

	while(1)
	{
	scanf("%d %d",&n,&m);
	if((n==0)&&(m==0))
		break;
	ans=n;

	for(i=1;i<=m;i++){
		scanf("%d %d",&p[i],&c[i]);	
	}

	for(i=m;i>=1;i--){
		if((n-p[i]+1-c[i])>ans){
		}else if(ans>=(n-c[i]))
			ans = ans-p[i]+1;
		else
			ans = ans+c[i];
	}
	printf("%d\n",ans);

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

#define REP(i, n) for(int i=0;i<(n);i++)

#define MAX_N 53
#define MAX_R 53

int p[MAX_R], c[MAX_R];
int card [MAX_N][2];
int n,r;

bool input(){
  cin>>n>>r;
  REP(i, r)cin>>p[i]>>c[i];
  return (n!=0);
}

void solve(){
    REP(i, n+1)card[i][0] = i;
    REP(i, n+1)card[i][1] = i;

    REP(i, r) {
      //REP(j, n)cout<<card[n-j][0]<<' ';
      //cout<<endl;
      REP(j, c[i]) {
        card[n-j][1] = card[n-p[i]+1-j][0];
      }

      REP(j, p[i]-1) {
        card[n-c[i]-j][1] = card[n-j][0];
      }

     // REP(j, n-c[i]-p[i])card[j+1][1] = card[j+1][0];

      REP(i, n)card[i+1][0] = card[i+1][1];
    }

    //REP(i, n)cout<<card[n-i][0]<<' ';
    cout<<card[n][0]<<endl;
}

int main (){
  while(input()){
    solve();
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    int n, r, p, c, top;
    int order[50][2];
    while (true) {
        cin >> n >> r;
        if (n == 0 && r == 0) {
            break;
        }
        top = n;
        for (int i = 0; i < r; ++i) {
            cin >> order[i][0] >> order[i][1];
        }
        for (int i= r - 1; i >= 0; --i) {
            p = order[i][0];
            c = order[i][1];
            if (top > n - p - c + 1) {
                if (top > n - c) {
                    top -= p - 1;
                }
                else {
                    top += c;
                }
            }
        }
        cout << top << endl;
    }
    return 0;
}

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