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 <vector>

using namespace std;

int main(){
	vector<int> cards;
	vector<int> ::iterator cardsIterator;
	vector<int> ::iterator shuffuleIterator;
	int n,r,p,c;

	while(cin >> n >> r, n && r){
		cards.clear(); //初期化
		// カードの山生成
		for (int i = 0; i < n; ++i){
			cards.push_back(i+1);
		}
		// シャッフル
		while(cin >> p >> c){
			cardsIterator = cards.end();
			cardsIterator -= p + (c - 1);
			while(c--){
				cards.push_back(*cardsIterator);
				cards.erase(cardsIterator);
			}
			if (r == 0){
				break;
			}
		}
		// 一番上のカード表示
		cout << cards.back() << endl;
	}
}

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

C++: #include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }


int main() {
    int n, r;
    while(1) {
        cin >> n >> r;
        if(n == 0 && r == 0) break;
        stack<int> yama;
        for(int i = 1; i <= n; ++i) yama.push(i);
        stack<int> hako;
        stack<int> ue;
        for(int i = 0; i < r; ++i) {
            int p, c; cin >> p >> c;
            for(int j = 0; j < p-1; ++j) {
                hako.push(yama.top());
                yama.pop();
            }
            for(int j = 0; j < c; ++j) {
                ue.push(yama.top());
                yama.pop();
            }
            while(!hako.empty()) {
                yama.push(hako.top());
                hako.pop();
            }
            while(!ue.empty()) {
                yama.push(ue.top());
                ue.pop();
            }
        }
        cout << yama.top() << endl;
    }
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

int count(vector<int> ls, int x) {
  const int n = ls.size();
  int left;
  int right;

  {{{ // search left
    if (ls[0] == x) {
      left = 0;
    } else {
      int l = 0;
      int r = n;
      // ls[l] < x <= ls[r]
      while (l < r) {
        if (l + 1 == r) {
          if (ls[l] == x) left = l;
          else if (ls[r] == x) left = r;
          else return 0;
          break;
        }
        int m = (l + r) / 2;
        if (ls[m] < x) {
          l = m;
        } else {
          r = m;
        }
      }
    }
  }}}

  {{{ // search right
    if (ls[n-1] == x) {
      right = n;
    } else {
      int l = 0;
      int r = n;
      // ls[l] <= x < ls[r]
      while (l < r) {
        if (l + 1 == r) {
          if (ls[l] == x) right = r;
          else if (ls[r] == x) right = r + 1;
          else return 0;
          break;
        }
        int m = (l + r) / 2;
        if (ls[m] <= x) {
          l = m;
        } else {
          r = m;
        }
      }
    }
  }}}

  return right - left;
}

int main() {

more:;
   int n, m; cin >> n >> m;
   if (!n && !m) return 0;

   vector<int> xs(n+2, -1);
   rep (i, n) xs[i] = n - i;

   rep (i, m) {
     int c, p; cin >> p >> c;
     rotate(xs.begin(), xs.begin() + p - 1, xs.begin() + c + p - 1);
   }
   cout << xs[0] << endl;
   goto more;

  return 0;
}

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

int main(){
	int p[50], c[50], n, r, pos, i;
	for( ; cin >> n >> r, n; ){
		for( i = 0; i < r; ++i ){
			cin >> p[i] >> c[i];
		}

		pos = 0;
		for( i = r; i--; ){
			if( pos < c[i] ){
				pos += p[i] - 1;
			}
			else if( pos < c[i] + p[i] - 1 ){
				pos -= c[i];
			}
		}
		cout << n - pos << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int N, R, p, c;
int main() {
  while (cin >> N >> R && N){
    vector<int> A(N,0);
    int i;
    for(i=0;i<N;i++){
      A[i]=N-i;
    }
    for(i=0;i<R;++i){
      cin >> p >> c;
      if (p==0){
        cout << "Incorrect input" << endl;
        exit(1);
      }
      rotate(A.begin(),A.begin()+p-1,A.begin()+p+c-1);
    }
    cout << A[0] << endl;
  }
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
const double PI=acos(-1.0);
//---------------------------------------------------------------------------//
int n,r;
int a[51],b[51],c[51];
int main(){
        while(1) {
                cin>>n>>r;
                if(n==0 && r==0) {
                        return 0;
                }
                for(int i=0; i<r; i++) {
                        cin>>a[i]>>b[i];
                }

                for(int i=0; i<n; i++) {
                        c[i]=i;
                }
                for(int i=0; i<r; i++) {
                        for(int j=0; j<a[i]-1; j++) {
                                c[j]+=b[i];
                        }
                        for(int j=a[i]-1; j<a[i]-1+b[i]; j++) {
                                c[j]-=(a[i]-1);
                        }
                }
                for(int i=0; i<n; i++) {
                        if(c[i]==0) {
                                cout<<n-i<<endl;
                        }
                }
        }
}

C++: #include<bits/stdc++.h>
#define INF INT_MAX/2
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

char a[50], b[50];
int main() {
	int n, r;
	while (scanf("%d%d", &n, &r), n) {
		for (int i = n - 1; i >= 0; i--)a[i] = n - i;
		rep(i, r) {
			int p, c; scanf("%d%d", &p, &c);
			memcpy(b, a, p - 1);
			memmove(a, a + p - 1, c);
			memcpy(a + c, b, p - 1);
		}
		printf("%d\n", (int)a[0]);
	}
}