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<stack>
#include<queue>

using namespace std;

void solve(stack <int> s , int r ){
  
  
  int p[r] ,c[r];

  for(int i = 0 ; i < r ; i++ ){
    cin >> p[i] >> c[i];
    p[i]--;
  }
  
  for(int i = 0 ; i < r ; i++ ){
    stack<int> s_sita;
    stack<int> s_ue;
    
    

    while(p[i]-- > 0){
      int a = s.top();
      s.pop();
      //cout << "push_sita:" << a << endl;
      //cout << "p:" << p[i] << endl;
      //cout << "size" << s.size() << endl;
      s_sita.push(a);
    }

    while(c[i]-- > 0){
      int a =s.top();
      s.pop();
      //cout << "push_ue:" << a << endl;
      //cout << "c" << c[i] << endl;
      //cout << "size" << s.size() << endl;
      s_ue.push(a);
    }
    
    while(!s_sita.empty()){
      s.push(s_sita.top());
      //cout << "s.push" << s_sita.top() << endl;
      s_sita.pop();
    }
    
    while(!s_ue.empty()){
      s.push(s_ue.top());
      //cout << "s.push" << s_ue.top() << endl;
      s_ue.pop();
    }
    
    //cout << "size" << s.size() << endl;

    //cout << endl;

  }
    
  cout << s.top() << endl;

  return;

}

int main(){

  int r , n ;

  cin >> n >> r;
  
  while(1){
    if(r == 0 || n == 0)
      break;

    else{
      stack <int> s;
      for(int i = 1 ; i <= n ; i++ ){
        s.push(i);
        //cout << i << endl;
      }
      solve(s,r);
    }
  }

  return 0;
}

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

using namespace std;

int top_search(int,int,int,int *);
int main(){
	int n,r,c,p;
	int cnt=0;
	int top[50000];
	while(1){
		cin>>n>>r;
		if(n==0&&r==0)
			break;
		int *hanahuda=new int[n+1];

		for (int i = n-1; i>=0 ; i--)
			hanahuda[i]=n-i;

		for(int i=0;i<r;i++){
			cin>>p>>c;
			top[cnt]=top_search(n,p,c,hanahuda);
		}
		delete[] hanahuda;
		cnt++;
	}
	for(int m=0;m<cnt;m++)
		cout<<top[m]<<endl;

	
	return 0;
}
int top_search(int n,int p,int c,int *hanahuda){
	int cnt=0;
	for(int k=p-1;k<p+c-1;k++){

		int nokori=hanahuda[k];

		for(int l=p-2;l>=0;l--){
			hanahuda[l+1]=hanahuda[l];
		}

		hanahuda[cnt]=nokori;
		cnt++;
	}
	return *hanahuda;
}

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

using namespace std;

int main(){
	while(true){
		int n,r;
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		int cards[2][n];
		for (int i=0;i<n;++i){
			cards[0][i] = n-i;
			cards[1][i] = n-i;
		}
		for (int i=0;i<r;++i){
			int f = i%2;
			int t = (i+1)%2;
			int p,c;
			cin >> p >> c;
			for (int l=0;l<p-1;++l){
				cards[t][l+c] = cards[f][l];
			}
			for (int l=p-1;l<p+c-1;++l){
				cards[t][l-(p-1)] = cards[f][l];
			}
			for (int l=p+c-1;l<n;++l){
				cards[t][l] = cards[f][l];
			}
		}
		int t = r%2;
		cout << cards[t][0] << endl;

	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,r,p,c,a[51],b[51];
  while(cin>>n>>r){
    if(n==0 && r==0)break;
    for(int i=0;i<n;i++)
      a[i]=n-i;
    for(int i=0;i<r;i++){
      cin>>p>>c;
      for(int i=0;i<n;i++)
	b[i]=a[i];
      for(int i=0;i<c;i++)
	a[i]=b[p-1+i];
      for(int i=0;i<p-1;i++)
	a[c+i]=b[i];
    }
    cout<<a[0]<<endl;
  }
  return 0;
}

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

using namespace std;

int main(){
    int n,r;
    while(cin>>n>>r,n){
        vector<int> hana,array;
        for(int i=n;i>=1;i--){
            hana.push_back(i);
        }
        for(int i=0;i<r;i++){
            int p,c;
            cin>>p>>c;
            for(int j=0;j<c;j++){
                array.push_back(hana[p-1+j]);
            }
            for(int j=p-2;j>=0;j--){
                hana[j+c]=hana[j];
            }
            hana=array;
            array.clear();
        }
        cout<<hana[0]<<endl;
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#define INF 100000000

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

static const double EPS = 1e-8;

const int tx[] = {0,1,0,-1};
const int ty[] = {1,0,-1,0};

int main(){
	int n,r;
	while(~scanf("%d %d",&n,&r)){
		if(n==r && r==0) break;
		vector<int> pile;
		for(int i=n;i>=1;i--){
			pile.push_back(i);
		}
		for(int i=0;i<r;i++){
			int p,c;
			scanf("%d %d",&p,&c);

			vector<int> tmp;
			for(int j=p-1;j<p+c-1;j++){
				tmp.push_back(pile[j]);
			}

			for(int j=0;j<p-1;j++){
				tmp.push_back(pile[j]);
			}

			for(int j=p+c-1;j<n;j++){
				tmp.push_back(pile[j]);
			}

			pile = tmp;
		}

		printf("%d\n",*pile.begin());
	}
}

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

using namespace std;

int main()
{
	int n, r;

	while (scanf("%d %d", &n, &r), n){
		vector<int> v;

		for (int i = 0; i < n; i++){
			v.push_back(n - i);
		}

		for (int i = 0; i < r; i++){
			int p, c;

			scanf("%d %d", &p, &c);

			stack<int> s;

			for (int j = p - 1; j < p + c - 1; j++){
				s.push(v[j]);
				v[j] = 0;
			}

			for (int j = n - 1; j > 0; j--){
				if (v[j] == 0){
					v[j] ^= v[j - 1];
					v[j - 1] ^= v[j];
					v[j] ^= v[j - 1];
				}
			}

			for (int j = c - 1; j >= 0; j--){
				v[j] = s.top();
				s.pop();
			}
		}

		printf("%d\n", v[0]);
	}

	return (0);
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it = (c).begin(); it != (c).end(); it++)
#define X first
#define Y second

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
    for(int n, r; cin >> n >> r, n;){
        string y;
        rep(i, n) y.pb('0' + n - i);

        while(r--){
            int p, c; cin >> p >> c;

            string str1 = y.substr(p - 1, c);
            string str2 = y.substr(0, p - 1);
            string str3 = y.substr(p + c - 1);
            y = str1 + str2 + str3;
        }

        cout << (int)(y.at(0) - '0') << endl;
    }

    return 0;
}

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

void cut(vector<int>& a, int p, int c) {
  vector<int> ptemp(p), ctemp(c);
  for (int i = 0; i < p; i++) {
    ptemp[i] = a[i];
  }
  for (int i = 0; i < c; i++) {
    ctemp[i] = a[p + i];
  }
  for (int i = 0; i < c; i++) {
    a[i] = ctemp[i];
  }
  for (int i = 0; i < p; i++) {
    a[i + c] = ptemp[i];
  }/*
  for (int i = 0; i < a.size();i++){
    printf("%2d", a[i]);
  }
  cout << endl;
  */
  return;
}

int main() {
  int n, r;
  while (1) {
    cin >> n >> r;
    if (n == 0) {
      break;
    }
    vector<int> a(n);
    iota(a.rbegin(), a.rend(), 1);
    // cout << a[0] << " " << a[1] << " " << a[2] << endl;
    int p, c;
    for (int i = 0; i < r; i++) {
      cin >> p >> c;
      p--;
      cut(a, p, c);
    }
    cout << a[0] << endl;
  }
  return 0;
}