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 <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
 
using namespace std;

void shuffle(int card[], int p, int c);

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

void shuffle(int card[], int p, int c)
{
    int hozon[50];
    for(int i = 0; i < p - 1; i++){
        hozon[i] = card[i];
    }
    for(int i = 0; i < c; i++){
        card[i] = card[i + p - 1];
    }
    for(int i = 0; i < p - 1; i++){
        card[c + i] = hozon[i];
    }
    return;
}

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

int main(){
	while(1){
		int n,r,p,c,s[n + 1];
		cin >> n >> r;
		if(n == 0 && r ==0)break;
		for(int i = 1; i <= n;++i){
			s[i] = i;
			}
			for(int j = 1; j <= r;++j){
				cin >> p >> c;
			    for(int k = 1;k <=c;++k){
			    		s[0] = s[n - p - c + 2];
				    for(int l = 1;l <= p + c - 2;++l){
					    s[n - p - c + 1 + l] = s[n - p - c + 2 + l];
					}
					s[n] = s[0];
			    }
		     }
		  cout << s[n] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
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[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<iostream>
using namespace std;
int main(){
  int n,r,fu[51];
  while(1){
    cin>>n>>r;
    if(n==0&&r==0)break;
    for(int i=1;i<=n;i++)fu[i]=n+1-i;
    for(int j=0;j<r;j++){
      int p,c,cp[50];
      cin>>p>>c;
      for(int k=0;k<c;k++){
	cp[k]=fu[p+k];
	}
      for(int k=p+c-1;k-c>=1;k--){
	fu[k]=fu[k-c];
      } 
      for(int k=1;k<=c;k++){
	fu[k]=cp[k-1];
	}
    }
    cout<<fu[1]<<endl;
  }
  return 0;
}

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

using namespace std;

int main(int argc, char const* argv[])
{
	int n, r, p, c;

	while(true) {
		cin >> n >> r;
		if(n == 0 && r == 0) break;

		vector<int> cards(n);

		for(int i = 0; i < n; ++i) {
			cards.at(n - i - 1) = i + 1;
		}

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

			vector<int> temp_p;
			vector<int> temp_c;

			copy_n(cards.begin(), p - 1, std::back_inserter(temp_p));
			copy_n(cards.begin() + p - 1, c, std::back_inserter(temp_c));

			copy(temp_c.begin(), temp_c.end(), cards.begin());
			copy(temp_p.begin(), temp_p.end(), cards.begin() + c);
		}

		std::cout << cards.at(0) << std::endl;
	}

	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n,r;
	while(cin>>n>>r,r){
		int cards[60],i;
		for(i=0;i<60;i++)cards[i]=i;
		for(i=0;i<r;i++){
			int a,b;
			cin>>a>>b;
			a--;
			int j;
			int c[60];
			for(j=0;j<60;j++){
				if(j<b){
					c[j]=cards[a+j];
				}else if(j<a+b){
					c[j]=cards[j-b];
				}else{
					c[j]=j;
				}
			}
			for(j=0;j<60;j++){
				cards[j]=c[j];
//cout<<cards[j]<<endl;
			}
//cout<<endl;
		}
		cout<<n-cards[0]<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  while(true){
  int n,r,p,c;
  cin>>n>>r;
  if(!n&&!r)break;
  string deck;
  for(int i=0;i<n;i++)
    deck = char(48+i)+deck;
  for(int i=0;i<r;i++){
    cin>>p>>c;
    deck = deck.substr(p-1,c)+deck.substr(0,p-1)+deck.substr(p+c-1);
  }
  cout<<(deck[0]-47)<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string.h>

using namespace std;

int main(){
	int n, r;
	int card[50], shuf[50];
	while(cin >> n >> r){
		if(!n) break;
		for(int i=0;i<n;i++) card[i] = n-i;
		for(int i=0;i<r;i++){
			int p, c; cin >> p >> c;
			int j=0;
			for(j=0;j<c;j++) shuf[j] = card[p-1+j];
			for(j=c;j<c+p-1;j++) shuf[j] = card[j-c];
			for(j=c+p-1;j<n;j++) shuf[j] = card[j];
			memcpy(card,shuf,sizeof(card));
		}
		cout << shuf[0] << endl;
	}
}

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

int main(){
    int n,r;
    while(true){
        cin >> n >> r;
        if(n == 0 && r== 0) break;
        int k[n];
        for(int i=0; i<n; i++)k[i]=n-i;
        int a[r],b[r];
        int c[n];
        for(int i = 0;i < r; i++)cin >> a[i] >> b[i];
        for(int i = 0;i < r; i++){
            for(int j = 0;j < b[i]; j++){
                c[j] = k[a[i]+j-1];
            }
            int d[100];
            for(int j = 0;j < a[i]-1;j++){
                d[j]=k[j];
            }
            for(int j=0;j<a[i]-1;j++){
                k[j+b[i]]=d[j];
            }
            for(int j = 0;j < b[i]; j++){
                k[j] = c[j];
            }
        }
        cout << k[0] << endl;
    }
}

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

int main() {
	int n,r;
	int p,c;
	int a[50];
	int b[50];
	while(1)
	{
		cin>>n>>r;
		if(n==0||r==0)
		{
			break;
		}
		int i=1;
		for(i=0;i<n;i++)
		{
			a[i]=n-i;
			b[i]=0;
		}
		i=0;
		while(r!=i)
		{
			cin>>p>>c;
			int j;
			for(j=0;j<c;j++)
			{
				b[j]=a[j+(p-1)];
			}
			for(j=0;j<p-1;j++)
			{
				b[c+j]=a[j];
			}
			for(j=0;j<(p-1)+c;j++)
			{
				a[j]=b[j];
			}
			i++;
		}
		cout<<a[0]<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    int n, r;
    while(cin >> n >> r && n*r != 0){
        int lst[n];
        for(int i=0; i<n; i++) {
            lst[i] = n-i;
        }
        for(int x=0; x<r; x++){
            int p, c;
            cin >> p >> c;
            if(p == 1) {
            }
            else {
                int sub[c];
                for(int j=0; j<c; j++) {
                    sub[j] = lst[p-1+j];
                }
                for(int k=p-2; k>=0; k--) {
                        lst[k+c] = lst[k];
                }
                for(int i=0; i<c; i++) {
                    lst[i] = sub[i];
                }
            }
        }
        cout << lst[0] << endl;
    }
}