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 <bits/stdc++.h>

using namespace std;

int n[10000]={},r[10000]={};
int p[10000][50] = {};
int c[10000][50] = {};
int i=0;

int d[50]={};
int e[50] = {}; //今の状態
int e2[50] = {};

int main(){
    while(1){
        scanf("%d %d",&n[i],&r[i]);
        if(n[i]== 0 && r[i]== 0){
            break;
        }
        for(int j=0;j<r[i];j++){
            scanf("%d %d",&p[i][j],&c[i][j]);
        }
        i++;
    }
    int times = i;
    for(i=0;i<times;i++){
        //初期化
        int s=0;
        for(int k = n[i]; k>0;k--){
            e[s] = k;
            s++;
        }
        for(int j=0;j<r[i];j++){
            s=0;
            for(int t=p[i][j]-1;t<p[i][j]+c[i][j]-1;t++){
                d[s] = e[t];
                s++;
            }
            for(int t = 0;t < n[i];t++){
                e2[t] = e[t];
            }
            for(int t = 0;t<c[i][j];t++){
                e[t] = d[t];
            }
            s = 0;
            for(int t=c[i][j];t<p[i][j]+c[i][j]-1;t++){
                e[t] = e2[s];
                s++;
            }


        }
        
        cout << e[0] << endl;
    }

    return 0;
}

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

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


int main(){
  int n, r;

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

    else{
    int hana[n];
    REP(i, n) hana[i]=n-i;

    REP(j, r){
      int p, c;
      cin >> p >> c;
      int tmp[c];
      REP(i, c) tmp[i] = hana[p+i-1];
      REP(i, p-1) hana[p-2-i+c] = hana[p-2-i];
      REP(i, c) hana[i] = tmp[i];
    }
    cout << hana[0] << endl;
  }
  }
return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n||m){
    string in;
    rep(i,n)in=(char)(i+49)+in;

    rep(i,m){
      int a,b;
      cin>>a>>b;
      //cout<<in<<endl;
      in=in.substr(a-1,b)+in.substr(0,a-1)+in.substr(a+b-1);
    }
    cout<<in[0]-'0'<<endl;
  }

}

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

struct list{
  int number;
  list *next;
};

void Insertlist(list **ptr, int newnumber);

void Insertlist(list ** ptr, int newnumber){
  if( *ptr == NULL || (*ptr)->number < newnumber){
    list *newcell;
    newcell = (list *)malloc(sizeof(list));
    newcell->number = newnumber;
    newcell->next = *ptr;
    *ptr = newcell;
  }else{
    Insertlist(&(*ptr)->next, newnumber);
  }
}

int main(){

  int n, r;

  while( cin >> n >> r ){

    if( n == 0 && r == 0) break;

    list *root = NULL;
    for(int i = n ; i > 0 ; i--){
      Insertlist(&root,i);
    }
 
    while( r ){
      int p,c;
      cin >> p >> c;

      list *ptr1 = root, *ptr2 = root,*ptr3,*ptr4;
      
      for(int i = 0 ; i < p-2; i++)
	ptr1 = ptr1->next;
      if(p > 1)
	ptr2 = ptr1->next;
      ptr3 = ptr2;
      for(int i = 0; i < c-1 ; i++)
	ptr3 = ptr3->next;
      ptr4 = ptr3->next;
      
      if(p>1){
	ptr1->next = ptr4;
	ptr3->next = root;
	root = ptr2;
      } 
      r--;
    }
    cout << root->number << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,r;
  while(cin>>n>>r,n+r!=0){
    queue<int> yama;
    queue<int> x;
    queue<int> y;
    queue<int> z;
    for(int i=n;i>=1;i--)
      yama.push(i);
    for(int i=0;i<r;i++){
      int p,c;
      cin>>p>>c;
      for(int i=1;i<=p-1;i++){
	x.push(yama.front());
	yama.pop();
      }
      for(int i=1;i<=c;i++){
	y.push(yama.front());
	yama.pop();
      }
      while(!yama.empty()){
	z.push(yama.front());
	yama.pop();
      }
      while(!y.empty()){
	yama.push(y.front());
	y.pop();
      }
      while(!x.empty()){
	yama.push(x.front());
	x.pop();
      }
      while(!z.empty()){
	yama.push(z.front());
	z.pop();
      }
    }
    cout<<yama.front()<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include<vector>
#include<string.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
using namespace std;

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

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main(void){
	int n, r;
	while(cin >> n >> r, n | r){
		int card[n];
		card[0] = n;
		for(int i = 1; i < n; i++)card[i] = card[i-1]-1;
		rep(i,r){
			int p, c;
			cin >> p >> c;
			int abv[p];
			for(int j = 0; j < p-1; j++){
				abv[j] = card[j];
			}
			for(int j = 0; j < c; j++){
				card[j] = card[p-1+j];
			}
			for(int j = 0; j < p-1; j++){
				card[c+j] = abv[j];
			}
		}
		cout << card[0] << endl;
	}

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}