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>

using namespace std;

int input() {
	int input[51][2];
	cin >> input[0][0] >> input[0][1];								
	if (input[0][0] == 0 && input[0][1] == 0) {
		return 0;
	}
	for (char pos = 1; pos <= input[0][1]; pos++) {
		cin >> input[pos][0] >> input[pos][1];
	}																

	int whtop = 1;													
	whtop = input[input[0][1]][0];
	input[0][1]--;
	while (input[0][1] != 0) {

		if (input[input[0][1]][1] >= whtop) {
			whtop = input[input[0][1]][0] + whtop - 1;
		}
		else {
			whtop = whtop - input[input[0][1]][1];
		}
		input[0][1]--;
	}
	return input[0][0]-whtop+1;
}




int main()
{
	int output[1000];
	char topos = 0;
	while (1) {
		int check;
		check=input();
		if (check == 0)break;
		else {
			output[topos] = check;
			topos++;
		}
	}

	char sendpos = 0;
	while (sendpos < topos) {
		cout << output[sendpos] << endl;
		sendpos++;
	}


}

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

int hanafuda[50], tmp[50];

int main()
{
    int n,c,p,r;
    while(cin >> n >> r && n && r) {
        for(int i = 0; i < n; i++)
            hanafuda[i] = n - i;
        

        for(int i = 0; i < r; i++) {
            cin >> p >> c;
            for(int i = 0; i < n; i++) 
                tmp[i] = hanafuda[i];

            for(int i = 0; i < c; i++) 
                hanafuda[i] = tmp[i + p - 1];
            
            for(int i = 0; i < p; i++)
                hanafuda[i + c] = tmp[i];
        }
        cout << hanafuda[0] << endl;
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double EPS = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int n, r;
int p, c;

int main() {
	while (cin >> n >> r, n && r) {
		if (n == 1) {
			cout << 1 << endl;
			continue;
		}

		vector<int> card;
		for (int i = n; i > 0; --i) card.push_back(i);

		rep(i, r) {
			cin >> p >> c;
			vector<int> tmp;
			rep(j, c) tmp.push_back(card[p - 1 + j]);
			rep(j, p - 1) tmp.push_back(card[j]);
			REP(j, p + c, n) tmp.push_back(card[j]);
			card = tmp;
		}
		cout << card[0] << endl;
	}
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
#include<deque>
using namespace std;

int main(){
	int n,r;
	while(scanf("%d%d",&n,&r),n){
		deque< int > DQ;
		for(int i = 0; i < n; i++){
			DQ.push_back(n-i);
		}
		for(int i = 0; i < r; i++){
			int p,c;
			scanf("%d%d",&p,&c);
			p--;c--;
			deque < int > :: iterator it;
			vector < int > sub;
			int cnt = 0;
			for(it = DQ.begin(); it != DQ.end(); it++){
				if(cnt >= p && cnt <= c+p){
					sub.push_back(DQ[cnt]);
					DQ.erase(it,it);
				}
				cnt++;
			}
			for(int j = 0; j < sub.size(); j++){
				DQ.push_front(sub[sub.size()-j-1]);
			}
		}
		printf("%d\n",DQ[0]);
	}
	return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  int n, r;
  while(1) {
    cin >> n >> r;
    if(n==0 && r==0) break;
    int num[n+1];
    FOR(i,0,n+1) num[i] = i;
    while(r--) {
      int p, c;
      scanf("%d %d\n", &p, &c);
      int tmp[c+p-1];
      FOR(i,0,c) {
        tmp[i] = num[n-(p-1)-i];
      }
      FOR(i,c,c+p-1) {
        tmp[i] = num[n-(i-c)];
      }
      FOR(i,0,c+p-1) num[n-i] = tmp[i];
    }
    printf("%d\n", num[n]);
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

int input() {
	int input[51][2];
	cin >> input[0][0] >> input[0][1];								//まずnとr
	if (input[0][0] == 0 && input[0][1] == 0) {
		return 0;
	}
	/*
	input[0][0] = 0;
	input[0][1] = 0;
	*/
	for (char pos = 1; pos <= input[0][1]; pos++) {
		cin >> input[pos][0] >> input[pos][1];
	}																//ここまで入力

	/*シャッフルもどし*/
	int whtop = 1;													//1番目≠要素
	whtop = input[input[0][1]][0];
	input[0][1]--;
	while (input[0][1] != 0) {

		if (input[input[0][1]][1] >= whtop) {
			whtop = input[input[0][1]][0] + whtop - 1;
		}
		else {
			whtop = whtop - input[input[0][1]][1];
		}
		input[0][1]--;
	}
	return input[0][0]-whtop+1;
}




int main()
{
	int output[100];
	char topos = 0;
	while (1) {
		int check;
		check=input();
		if (check == 0)break;
		else {
			output[topos] = check;
			topos++;
		}
	}

	char sendpos = 0;
	while (sendpos < topos) {
		cout << output[sendpos] << endl;
		sendpos++;
	}


}

C++: #include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


int main(void){
	int ans[100],cnt=0;
	while(1){
		int n,r;
		cin>>n>>r;
		if(n==0)break;
		int p[50],c[50];
		irep(i,r)cin>>p[i]>>c[i];//?????????????????????
		int pos=0;
		rep(i,r){
			if(pos<c[i]){
				pos+=p[i]-1;
			}else if(pos<c[i]+p[i]-1){
				pos-=c[i];
			}
		}
		ans[cnt]=n-pos;
		cnt++;
	}
	rep(i,cnt)cout<<ans[i]<<endl;
	return 0;
}