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 <vector>
using namespace std;

int main(){
    int n, m, p, c;
    while(cin >> n >> m){
        if(n * m == 0) break;
        vector<int> mou(n);
        for(int i = 0;i<n;i++) mou[i] = n-i;
        for(int i = 0;i<m;i++){
            vector<int> tmp(n);
            cin >> p >> c;
            for(int j = 0;j<c;j++){
                tmp[j] = mou[p+j-1];
            }
            for(int j = 0;j<p-1;j++){
                tmp[c+j] = mou[j];
            }
            for(int j = 0;j<p+c-1;j++){
                mou[j] = tmp[j];
            }
            // for(int j = 0;j<n;j++) cout << tmp[j];
            // cout << " ";
            // for(int j = 0;j<n;j++){cout << mou[j];}
            // cout << endl;
        }
        cout << mou[0] << endl;
    }
    return 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;
}