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>
#include<string>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,r,p,c;
	while(1){
		cin>>n>>r;
		if(n==0 && r==0)break;
		int dt[n];
		int alt[n];
		rep(i,n)alt[i]=0;
		for(int i=n;i>0;i--){
			dt[n-i]=i;
			alt[i-1]=0;
		}
		rep(i,n)cout<<dt[i]<<" ";
		cout<<endl;
		rep(j,r){
			cin>>p>>c;
			loop(i,p+c-1,n)alt[i]=dt[i];
			rep(i,p-1)alt[c+i]=dt[i];
			loop(i,p-1,p+c-1)alt[i-p+1]=dt[i];
			rep(i,n)dt[i]=alt[i];
		}
		cout<<dt[0]<<endl;
	}
	return 0;
}

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

int solve(int n,int r){
    vector<int> m;
    for(int i=0;i<n;i++){
        m.push_back(i);
    }
    for(int i=0;i<r;i++){
        int p,c;
        scanf("%d %d",&p,&c);
        rotate(m.begin(),m.begin()+p-1,m.begin()+p+c-1);
    }
    return n-m[0];
}

int main(){
    while(1){
        int n,r;
        scanf("%d %d",&n,&r);
        if(n==0&&r==0) return 0;
        printf("%d\n",solve(n,r));
    }
}

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 whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        pair<int, int> n; cin >> n.first >> n.second;
        if(n.first == 0 and n.second == 0) return 0;
        else{
            vector<int> Card(n.first);
            int tmp = n.first;
            for(int i = 0; i < n.first; i++){
                Card[i] = tmp;
                tmp--;
            }
            REP(i, n.second){
                pair<int, int> cut; cin >> cut.first >> cut.second;
                vector<int> New(0);
                for(int i = cut.first - 1; i < cut.first + cut.second - 1; i++) New.push_back(Card[i]);
                REP(i, cut.first - 1) New.push_back(Card[i]);
                FOR(i, cut.first + cut.second - 1, n.first) New.push_back(Card[i]);
                REP(i, n.first) Card[i] = New[i];
            }
            cout << Card[0] << endl;
        }
    }
}

C++: #include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<functional>
using namespace std;

#define INF 1<<21
#define MOD 1000000007

int main(void) {
  int n, r;
  int c, p;
  int yama[51];
  queue<int> s;

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

	for (int i = 0; i < n; i++) {
	  yama[i] = i + 1;
	}

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

	  for (int j = 0; j < c; j++) {
		s.push(yama[n - p - j]);
	  }

	  for (int j = n - p + 1; j < n; j++) {
		yama[j - c] = yama[j];
	  }

	  for (int j = 1; j <= c; j++) {
		yama[n - j] = s.front();
		s.pop();
	  }
	}
	cout << yama[n - 1] << endl;
  }
}

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]-c[i]-1)>=ans){
		}else if(ans>=(n-c[i]+1)){
			ans = ans-p[i]+1;
		}else
			ans = ans+c[i];
		}
	printf("%d\n",ans);
	}

	}
	return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int32 n, r;
	while(cin >> n >> r && n && r){
		vector<int32> x(n);
		REP(i, n) x[i] = i;
		REP(i, r){
			int32 p, c;
			cin >> p >> c;
			p--;
			vector<int32> nx(n);
			REP(j, n){
				if(x[j] < p) nx[j] = x[j]+c;
				else if(x[j] < p+c) nx[j] = x[j]-p;
				else nx[j] = x[j]; 
			}
			swap(nx, x);
		}
		int32 res = 0;
		REP(i, n) if(x[i] == 0) res = n-i;
		cout << res << endl;
	}
}

C++: #include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int n, r;
  while (cin >> n >> r && n && r) {
    vector<int> card(n);
    vector<int> tmp(n);

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

C++: #include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(itr,data) for(__typeof((data).begin()) itr=(data).begin();itr!=(data).end();++itr)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long UInt64;
typedef long long Int64;

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

typedef pair<int ,int > P;

int n,r;

void solve() {
    int ary[60]={};
    rep(i,n+1) ary[i]=n-i+1;

    rep(i,r) {
        int p,c;
        cin>>p>>c;
        p--;
        int tmp[60]={};
        for(int j=1;j<=p;j++) tmp[j]=ary[j];
        for(int j=1;j<=c;j++) swap(ary[j],ary[j+p]);
        for(int j=c+1;j<=c+p;j++) ary[j]=tmp[j-c];
    }
    cout<<ary[1]<<endl;
}

int main() {
    while(cin>>n>>r) {
        if(!(n+r)) return 0;
        solve();
    }
    return 0;
}

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

int main(){

  int N,n,p,c,t;
  int a[51],b[51];
  while(1){
  cin>>N>>n;
  if(N+n==0) break;
  for(int i=1;i<=N;i++){
    a[i]=N+1-i;
    b[i]=N+1-i;
  }

  for(int i=1;i<=n;i++){
    cin>>p>>c;
    t=1;
    for(int j=p;j<p+c;j++){
      b[t]=a[j];
      t++;
    }
      for(int s=1;s<p;s++){
	b[t]=a[s];
	t++;
      }
      for(int w=1;w<=N;w++){
	a[w]=b[w];
      }  
  }

  cout<<b[1]<<endl;
  }
  return 0;
}

C++: #include<iostream>

void showDeck(int *a,int l){
	std::cout << "[";
	for(int i=0;i<l;i++){
		std::cout << a[i] ;
		if(i!=l-1) std::cout << ", ";
	}
	std::cout << "]" << std::endl;
}
int main(void) {
	int n,r;
	int p,c;
	int a[2];
	while(true){
		std::cin >> n;
		std::cin >> r;
		if(n == 0 || r == 0) break;
		int deck[n];
		for(int i=0;i<n;i++){
			deck[i] = n-i;
		}
		for(int ii=0;ii<r;ii++){
			std::cin >> p;
			std::cin >> c;
			int set1[p-1];
			int set2[c];
			for(int i=0; i<p-1;i++){
				set1[i]=deck[i];
			}
			for(int i=0; i<c;i++){
				set2[i]=deck[p-1+i];
			}
			// showDeck(deck,n);
			// showDeck(set1,p-1);
			// showDeck(set2,c);
			for(int i=0;i<c;i++){
				deck[i]=set2[i];
			}
			for(int i=0;i<p-1;i++){
				deck[c+i]=set1[i];
			}
			// showDeck(deck,n);
		}
		std::cout << deck[0] << std::endl;
	}
	return 0;
}