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>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit
#include <cstdio>	// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define DEBUG 0

using namespace std;

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

int main()
{
//	cut here before submit 
//	freopen ("testcase.HS5", "r", stdin );
	int n, r;
	while (cin >> n >> r && n && r ){
		vector <vector <P> > before (r, vector <P> (3 ) );
		vector <vector <P> > after  (r, vector <P> (3 ) );
		int cnt = 0;
		rep (i, r ){
			int p, c;
			cin >> p >> c;
			if (p == 1 ) continue;
			before[cnt][0] = P (1, p - 1 );
			before[cnt][1] = P (p, p + c - 1 );
			before[cnt][2] = P (p+c, n );
			after[cnt][0] = before[cnt][1];
			after[cnt][1] = before[cnt][0];
			after[cnt][2] = before[cnt][2];
			cnt++;
		} // end rep
		int curr = after[cnt-1][0].first;
#if DEBUG
		cout << "curr: " << curr << endl;
		rep (i, cnt ){
			rep (j, 3 ){
				cout << '(' << before[i][j].first << ',' << before[i][j].second << ')';
			} // end rep
			cout << endl;
			rep (j, 3 ){
				cout << '(' << after[i][j].first << ',' << after[i][j].second << ')';
			} // end rep
			cout << endl;
 		} // end rep
#endif
		for (int i = cnt - 2; i >= 0; i-- ){
			// ÇÌRÌ½ÔÚ©ðTõ
			int prev = 0;
			rep (j, 3 ){
				int cn = after[i][j].second - after[i][j].first + 1; // j ÌRÌJ[hÌ
#if DEBUG
				cout << "cn: " << cn << endl;
#endif
				if (prev < curr && curr <= prev + cn ){ // ±ÌRÉJ[hª é
					curr = after[i][j].first + curr - 1 - prev;
#if DEBUG
					cout << "prev: " << prev << endl;
					cout << "curr: " << curr << endl;
#endif
					break;
				} // end if
				prev += cn;
			} // end rep
		} // end for
#if DEBUG
		cout << "curr: " << curr << endl;
#endif
		int res = n - curr + 1;
		cout << res << endl;	
	} // end loop
		
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int d[51];
int cop[51];
int main()
{
    int n, r;
    while (cin >> n >> r)
    {
        if (n == 0)
            break;
        for (int i = 0; i < n; i++)
            d[i] = n - i;
        for (int i = 0; i < r; i++)
        {
            int p, c;
            cin >> p >> c;
            for (int j = 0; j < c; j++)
                cop[j] = d[p - 1 + j];
            for (int j = p - 2; j >= 0; j--)
            {
                d[j + c] = d[j];
            }
            for (int j = 0; j < c; j++)
                d[j] = cop[j];
        }
        cout << d[0] << endl;
    }
}

C++: #include <cstdio>
int main(){
	while(1){
        int n,m;
        int num[51][51];
        int a,b;
	scanf("%d %d",&n,&m);
	if(!n) break;
	for(int i=1;i<=n;i++){
		num[i][0]=i;
	}
	for(int i=1;i<=m;i++){
		scanf("%d %d",&a,&b);
		for(int k=1;k<=b;k++){
			num[k][i]=num[a+k-1][i-1];
		}
		for(int k=b+1;k<=a+b-1;k++){
			num[k][i]=num[k-b][i-1];
		}
		for(int k=a+b;k<=n;k++){
			num[k][i]=num[k][i-1];
		}
	}
	printf("%d\n",n-num[1][m]+1);
	}
	return 0;
}

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

int main(){
	while(1){
		int n,r;
		cin>>n>>r;
		if(n==0&&r==0)break;
		vector<int> a(n);
		for(int i = 0;i<n;i++){
			a[i]=n-i-1;
		}
		for(int i = 0;i<r;i++){
			int p,c;
			cin>>p>>c;
			for(int j=0;j<n;j++){
				if(a[j]<p-1){
					a[j]+=c;
				}else if(a[j]<p-1+c){
					a[j]-=(p-1);
				}
			}
			//cout<<i<<endl;
		}
		//cout<<"a"<<endl;
		for(int i=0;i<n;i++){
			if(a[i]==0)cout<<i+1<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <queue>
#include <numeric>
#include <algorithm>
using namespace std;

int main(){

	int n, r;
	while(cin >> n >> r, n|r){

		vector<int> now(100), next(100);

		for(int i=0; i<n; i++){
			now[n-1-i] = i+1;
		}

		for(int i=0; i<r; i++){
			int p, c; cin >> p >> c;
			for(int j=0; j<n; j++){	
				if(j<c){
					next[j] = now[p-1+j];
				}else if(j<c+p-1){
					next[j] = now[j-c];
				}else{
					next[j] = now[j];
				}
			}
			now = next;
		}
		cout << now[0] << endl;
	}

	return 0;
}

C++: #include <cstdio>

int main()
{
    int deck[50] = {}, tam[50] = {}, num, times, p, c;

    while (1)
    {
        scanf("%d %d", &num, &times);
        if (num == 0 && times == 0)
        {
            break;
        }
        for (int i = 0; i < num; i++)
        {
            deck[i] = num - i;
        }

        for (int i = 0; i < times; i++)
        {
            scanf("%d %d", &p, &c);
            for (int j = 0; j < p - 1; j++)
            {
                tam[j] = deck[j];
            }
            for (int j = 0; j < c; j++)
            {
                deck[j] = deck[j + p - 1];
            }
            for (int j = 0; j < p - 1; j++)
            {
                deck[c + j] = tam[j];
            }
        }
        printf("%d\n", deck[0]);
    }
}

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

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

int main() {
  while(true) {
    int ncard, r;
    scanf("%d%d", &ncard, &r);
    if(ncard == 0 && r == 0) break;
    vector<int> cards(ncard);
    for(int i = 0; i < ncard; ++i) cards[i] = ncard - i;
    for(int i = 0; i < r; ++i) {
      int p, c;
      vector<int> results;
      scanf("%d%d", &p, &c);
      for(int j = p - 1; j < p - 1 + c; ++j) {
        results.push_back(cards[j]);
      }
      for(int j = 0; j < p - 1; ++j) {
        results.push_back(cards[j]);
      }
      for(int j = p - 1 + c; j < ncard; ++j) {
        results.push_back(cards[j]);
      }
      cards = results;
    }
    cout << cards[0] << endl;
  }
  return 0;
}

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

using namespace std;
int main(){
  int n,r;
  while(cin >> n >> r,n!=0){
    int s[n];
    for(int i=0;i<n;i++){
      s[i] = n -i;
    } 
    int p,c;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      int tmp[c];
      for(int i=0;i<c;i++){
	tmp[i] = s[p+i-1];
      }
      for(int i=0;i<p-1;i++){
	s[c+p-2-i] = s[p-2-i];
      }
      for(int i=0;i<c;i++){
	s[i] = tmp[i];
      }
    }
    cout << s[0] << endl;
  }
}