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<string>
#include <algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<set>
using namespace std;
using ll = long long;

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 <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
  
int main()
{
	int n,m;
	int p[51]={0};
	int c[51]={0};
	int i;
	int ans;

	while(1)
	{
	scanf("%d %d",&n,&m);
	if((n==0)&&(m==0))
		break;
	ans=n;

	for(i=1;i<=m;i++){
		scanf("%d %d",&p[i],&c[i]);	
	} 

	for(i=m;i>=1;i--){
		if(p[i]!=1){
		if((n-p[i]+1-c[i])>ans){
		}else if(ans>(n-c[i])){
			ans = ans-p[i]+1;
		}else
			ans = ans+c[i];
		}
	}
	printf("%d\n",ans);

	}
	return 0;
}

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

typedef long long int64;
typedef int int32;
typedef char int8;

#define rep(i,j) for(int i=0;i<j;i++)
#define repeat(i,j,k) for(int i=(j),i<(k);i++)
#define repeat_eq(i,j,k) for(int i=(j),i<=(k);i++)
#define rev_rep(i,j,k) for(int i=(j)-1;i>=k;i--)
#define all(v) (v).begin(),(v).end()

const int INF=1<<30;//=10E10

void mycopy(int *out,int *in,int num){
  copy(in,in+num,out);
}

int main()
{
  while(true){
    int n,r;cin>>n>>r;
    if(!n && !r)break;
    int card[2][51];
    rep(i,n)card[0][i]=n-i;//初期化
    rep(i,r){
      int p,c;cin>>p>>c;
      
      mycopy(card[1],card[0]+p-1,c);
      mycopy(card[1]+c,card[0],p-1);
      mycopy(card[0],card[1],p+c-1);
      
    }
    cout<<card[0][0]<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e17;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)




int main() {
    int n, r;
    cin >> n >> r;
    
    while(n != 0 || r != 0){
        vector<int> k(n);
        REP(i, n){
            k[i] = n - i;
        }
        
        REP(i, r){
            int p, c;
            cin >> p >> c;
            vector<int> t(c);
            REP(j, c){
                t[j] = k[p - 1 + j];
            }
            for(int j = p + c - 2; j >= c; j--){
                k[j] = k[j - c];
            }
            REP(j, c){
                k[j] = t[j];
            }
        }
        
        cout << k[0] << endl;
        
        cin >> n >> r;
    }
}

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

#define loop(i) for(int lp = 0; (lp) < (i); (lp) ++)

using namespace std;

int main() {
  int n, r, p, c;
  vector<int> card;
  
  while(cin >> n >> r, n) {
    card.clear();
    for(int i = n; i > 0; i --) {
      card.push_back(i);
    }
    
    for(int i = 0; i < r; i ++) {
      cin >> p >> c;

      loop(c) {
	for(int j = (p-1)+(c-1); j > 0; j --) {
	  swap(card[j], card[j-1]);
	}
      }
    }

    cout << card[0] << endl;
  }
  return 0;
}

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


int main(){
	while (true){
		int n, r,a[50];
		cin >> n >> r;
		if (n == 0 && r == 0){ break; }
		for (int i = 0; i < 50; i++){
			a[i] = i;
		}

		for (int i = 0; i < r; i++){
			int p, c, b[50];
			cin >> p >> c;
			for (int j = 0; j < p; j++){
				b[j] = a[j];
			}
			for (int j = 0; j < c; j++){
				a[j] = a[p + j];
			}
			for (int j = 0; j < p; j++){
				a[c + j] = b[j];
			}
		}

		cout << a[0] << endl;
	}
	return 0;
}

C++: #include <stdio.h>

int main(void){
  int n, r, p, c;
  while(1){
    scanf("%d%d", &n, &r);
    if (n==0 && r==0){
      break;
    }
    int card[n], temp[n];
    for(int i=0;i<n;i++){
      card[i] = n-i;
    }
    for(i=0;i<r;i++){
      scanf("%d%d", &p, &c);
      //カットの処理
      for(i=p-1;i<p+c-1;i++){
        temp[i-p+1] = card[i];
      }
      for(i=0;i<p-1;i++){
        card[p+c-2-i] = card[p-2-i];
      }
      for(i=0;i<c;i++){
        card[i] = temp[i];
      }
    }
    printf("%d", card[0]);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};



int main(){
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0) break;
		vi a(n);
		for(int i=0;i<n;i++) a[i]=n-i;
		for(int i=0;i<m;i++){
			int x,y;
			cin>>x>>y;
			vi b;
			x--;
			for(int i=0;i<y;i++) b.push_back(a[x+i]);
			for(int i=0;i<x;i++) b.push_back(a[i]);
			for(int i=x+y;i<n;i++) b.push_back(a[i]);
			a=b;
		}
		cout<<a[0]<<endl;
	}
}

C++: #include <stdio.h>

void c_copy(int c_tmp[], int data[], int p, int c, int n) {
  int i = 0;
  for (i = 0; i < c; i++) {
    c_tmp[i] = data[n-p+i-c+1];
    //    printf("i =%d n=%d n-p+i-c = %d\n",i,n,n-p+i-c+1);
  }
}

void move(int data[], int p, int c, int n) {
  int i;
  for (i = n-p+1; i < n; i++) {
    data[i-c] = data[i];
  }
}

void tmp_in(int c_tmp[], int data[], int p, int c, int n) {
  int i;  
  for (i = n-c; i < n; i++) {
    data[i] = c_tmp[i-n+c];
  }
}

void print(int data[], int n) {
  for (int i = 0; i < n; i++) {
    printf("%d ",data[i]);
  }
  puts("");
}

int main(void) {
  int data[200];
  int n[1000];
  int r[1000];
  int p[1000][200];
  int c[1000][200];
  int c_tmp[1000][200];
  int i = 0, j = 0;
  int N;

  while (1) {
    scanf("%d", &n[i]);
    scanf("%d", &r[i]);
    if (n[i] == r[i] && n[i] == 0) {
      break;
    }
    for (j = 0; j < r[i]; j++) {
      scanf("%d", &p[i][j]);
      scanf("%d", &c[i][j]);
    }
    i++;
  }
  N = i;

  
  for (i = 0; i < N; i++) {
    for (j = 0; j < 200; j++) {
      data[j] = j+1;
    }
    for (j = 0; j < r[i]; j++) {
      // print(data, n[i]);//
      
      c_copy(c_tmp[i], data, p[i][j], c[i][j], n[i]);//
      // printf("c_copy = ");
      // print(c_tmp[i], n[i]);//
      
      move(data, p[i][j], c[i][j], n[i]);
      // printf("move\n");
      // print(data, n[i]);
      
      tmp_in(c_tmp[i], data, p[i][j], c[i][j], n[i]);
      //    print(data, n[i]);
      // puts("");
    }
    printf("%d\n",data[n[i]-1]);
  }
  
  return 0;
}