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 n,r,a,b;
int t[100];
int u[100],size;
int main(){
  while(cin>>n>>r&&n&&r){
    for(int i=0;i<n;i++)t[i]=n-i;
    for(int i=0;i<r;i++){
      cin>>a>>b;
      for(int j=0;j<b;j++)u[j]=t[j+a-1];
      for(int j=a-2;j>=0;j--)t[j+b]=t[j];
      for(int j=0;j<b;j++)t[j]=u[j];
    }
    cout<<t[0]<<endl;
  }
  return 0;
}

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

int main()
{
	int n, r, p, c;
	while (true) {
		cin >> n >> r;

		if (n == 0 && r == 0) break;
		vector<int> cards;
		for (int i = 1; i <= n; i++) {
			cards.push_back(i);
		}

		for (; r > 0; r--) {
			cin >> p >> c;

			p = n - p - c + 1;
			for (; c > 0; c--) {
				cards.push_back(cards[p]);
				cards.erase(cards.begin() + p);
			}
		}
		cout << cards.back() << '\n';
	}
	return 0;

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#define rep(i,l,n) for(int i=(l);i<(n);i++)

int n,r,i,card[55],change[55]={0};

void shuffle(int p,int c){
	rep(i,1,c+1) change[i]=card[p-1+i];
	rep(i,1,p) change[c+i]=card[i];
	rep(i,1,c+p) card[i]=change[i];
}
int main(void){
	int c,p;
	while(1){
		r=0;
		scanf("%d %d",&n,&r);
		//printf("%d %d\n",n,r);
		if(n==0 && r==0) break;
		rep(i,1,n+1) card[i]=n+1-i;
		rep(i,0,r){
			scanf("%d %d",&p,&c);
			//printf("pc %d %d %d\n",r,p,c);
			shuffle(p,c);
		}
		printf("%d\n",card[1]);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


void printv(vector<int> v) {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i] << " ";
	}
	cout << endl;
}
int main() {
	
	while(1) {
		int n,r; cin >> n >> r;
		if(n + r == 0) {
			break;
		}

		vector<int> H(n,0);
		for (int i = 0; i < n; i++) {
			H[i] = n - i;
		}

		for (int j = 0; j < r; j++) {
			vector<int> a;
			vector<int> b;
			int p,c; cin >> p >> c;
			for (int i = 0; i < p-1; i++) {
				a.push_back(H[i]);
			}
			//cout << "a" << endl;
			//printv(a);
			for (int i = p - 1; i < p - 1 + c; i++) {
				b.push_back(H[i]);
			}
			//cout << "b" << endl;
			//printv(b);
		
			for (int i = 0; i < c; i++) {
				H[i] = b[i];
			}
			//cout << "H1" << endl;
			//printv(H);
			for (int i = 0; i < p - 1; i++) {
				H[c + i] = a[i];
			}
			//cout << "H2" << endl;
			//printv(H);
		}
		cout << H[0] << endl;
	}


	return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n,r;

  while(cin >> n >> r && n != 0 && r != 0){
    int card[51],temp[51],p,c;

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

    while(r--){
      cin >> p >> c;
      int i;
      for(i=p;i < p+c;i++){
        temp[i-p+1] = card[i];
      }

      for(i=1;i<p;i++){
        temp[i+c] = card[i];
      }

      for(i=p+c;i < n+1;i++){
        temp[i] = card[i];
      }

      for(i=1;i<n+1;i++){
        card[i] = temp[i];
      }
    }

    cout << card[1] << endl;
  }

  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;
int x[100];
int y[100];
int card [100];
int n,r;
int ans[1000];
int counter;
bool input(){
    for(int i=0;i<100;i++){
    x[i]=0;
    y[i]=0;
    }
    cin >>n>>r;
    for(int i=0;i<r;i++){
    cin>>x[i]>>y[i];
    }
  if(n==0){
    return false;
    }
    else{
     return true;
    }
}
void solve(){
  for (int i=0;i<100;i++){
    cout<<x[i]<<y[i]<<endl;
  }
    for(int i=0;i<100;i++){
        card[i]=i+1;
    }
    for(int i=0;i<r;i++){
        for(int k=0;k<y[i];k++){
            int a=card[x[i]+y[i]-2];
            for(int j=x[i]+y[i]-1;j>0;j--){
                card[j]=card[j-1];
            }
            card[0]=a;
       
        }
    for(int j=1;j<=y[i]/2;j++){
      int remainder=card[j];
      card[j]=card[y[i]-j];
      card[y[i]-j]=remainder;
}
    }
    cout<<card[0]<<endl;
    ans[counter]=card[0];
    counter+=1;
}
    
    
    
int main (){
counter=0;
    while(input()){
    solve();
    }
for(int j=0;j<=counter;j++){
//cout<<ans[counter]<<endl;
}
return 0;
}

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

C++: #include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RFOR(i, a, b) for (int i=a;i>=b;--i)
#define ll long long
#define all(a) a.begin(),a.end()
#define ull unsigned long long
#define pb(x) push_back(x)
#define dbg(x) cout<<#x<<" : "<<(x)<<endl;
using namespace std;
const int INF = 1500000000;
const double PI = 3.14159265359;
const int mod = 1000000000 + 7;

int n, r, p[50], c[50], d[50], tmp[50];

void solve() {
  rep(i, r) {
    rep(j, p[i]-1 + c[i]) tmp[j] = d[j];
    rep(j, c[i]) {
      d[j] = tmp[p[i]-1 + j];
    }
    rep(j, p[i] - 1) {
      d[c[i] + j] = tmp[j];
    }
  }
  printf("%d\n", d[0]);
}

int main() {
  while(true) {
    scanf("%d %d", &n, & r);
    if (!n && !r) break;
    rep(i, n) d[i] = n - i;
    rep(i, r) scanf("%d %d", &p[i], &c[i]);
    solve();
  }
  return 0;
}

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

using namespace std;

int main(void) {
  vector<int> v;
  int n,r;
  int p,c;
  while(true) {
    cin >> n >> r;
    if(n == 0 && r == 0)
      break;
    v.clear();
    for(int i = 0; i < n; i++)
      v.push_back(i + 1);
    for(int i = 0; i < r; i++) {
      cin >> p >> c;
      p -= 1;
      rotate(v.rbegin(), v.rbegin() + p, v.rbegin() + p + c);
    }
    cout << v.back() << endl;
  }
  return 0;
}

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

int main()
{
	int n, r, p, c;
	while (true) {
		cin >> n >> r;

		if (n == 0 && r == 0) {
			break;
		}
		vector<int> cards;
		for (int i = 1; i <= n; i++) {
			cards.push_back(i);
		}

		for (; r > 0; r--) {
			cin >> p >> c;

			p = n - p - c + 1;
			for (; c > 0; c--) {
				cards.push_back(cards[p]);
				cards.erase(cards.begin() + p);
			}
		}
		cout << cards[0] << '\n';
	}
	return 0;
}