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 <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, r;
    while (cin >> n >> r, n) {
        vector<int> cards(n);
        for (int i = 0; i < n; i++) cards[i] = n - i;
        while (r--) {
            int p, c; cin >> p >> c; p--;
            vector<int> blue(cards.begin(), cards.begin() + p);
            vector<int> yellow(cards.begin() + p, cards.begin() + p + c);
            while (p--) cards[p + c] = blue.back(), blue.pop_back();
            while (c--) cards[c] = yellow.back(), yellow.pop_back();
		}
        cout << cards.front() << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
#define M 50

int main(void)
{
	int n,r;
	int p,c;
	int i,j,k,l;
	int a[M],temp[M];
	
	for(;;)
	{
		scanf("%d %d",&n,&r);
		if(n==0 && r==0) break;
		
		for(i=0; i<n; i++)
		{
			a[i]=i+1;
			temp[i]=i+1;
		}
		
		for(j=0; j<r; j++)
		{
			scanf("%d %d", &p, &c);
			for(i=0; i<n; i++)
			{
				temp[i]=a[i];
			}
			for(k=0; k<c; k++)
			{
				a[n-1-k]=a[n-p-k];
				for(l=0; l<c;l++)
				{
					a[n-p-k+l]=temp[n-p-k+1+l];
				}
			}
			
		}
		printf("%d\n",a[n-1]);
	}
	
	
	return 0;
}

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

using namespace std;

int main(){
	int n,r;
	
	while(cin >> n >> r){
		if(!(n|r)) break;
		int pos = 0;
		vector<pair<int,int> > inst(r);
		for(int i=0;i<r;i++){
			cin >> inst[i].first >> inst[i].second;
		}
		
		reverse(inst.begin(), inst.end());
		
		for(int i=0;i<r;i++){
			if(pos < inst[i].second){
				pos += inst[i].first-1;
			}else if(pos < inst[i].first + inst[i].second-1){
				pos -= inst[i].second;
			}
		}
		cout << n - pos << endl;
	}
}

C++: #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;

    while(true){
        ll n,r;
        cin>>n>>r;
        if(n==0&&r==0) break;
        vll v(n);
        rep(i,n) v[i]=n-i;
        rep(i,r){
            ll p,c;
            cin>>p>>c;
            vll t(p-1),s(c);
            rep(i,p-1) t[i]=v[i];
            rep(i,c) s[i]=v[p-1+i];
            rep(i,c) v[i]=s[i];
            rep(i,p-1) v[c+i]=t[i];
        }
        cout<<v[0]<<endl;
    }

    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
vector <string> v;
vector<int> ans;
string s;
vector<int> yama;
int main(){
  int n,r;
  cin >> n>>r;
  while((n != 0)&&(r != 0)){
    int p,c;

    for(int i = n; i > 0;i--){
      yama.push_back(i);
    }
    for (int  i = 0 ; i< r;i++){
      cin >> p>>c;
      vector<int> cpy(yama.begin()+p,yama.begin()+c-1);
      yama.erase(yama.begin()+p,yama.begin()+c-1);
      copy(yama.begin(),yama.end(),back_inserter(cpy));
    }
    ans.push_back(yama.front());
    cin >> n>>r;
  }

  for (int i = 0 ;i < (int)ans.size(); i++){
    cout << ans[i]<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	int n,r,p,c,t[50],s[50];
	while(true){
		cin >> n >> r;
		if(n==0 && r==0) return 0;
		for(int i=0;i<n;i++)
			t[i]= n-i;
		for(int i=0;i<r;i++){
			cin >> p >> c;
			for(int j=0;j<c;j++)
				s[j]=t[p-1+j];
			for(int j=0;j<p-1;j++)
				s[j+c]=t[j];
			for(int j=p+c-1;j<n;j++)
				s[j]= t[j];
			for(int j=0;j<n;j++)
				t[j]=s[j];

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

}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);

int main() {
	int n, r, p, c;
	while (cin >> n >> r&&n&&r) {
		vector<int> vec;
		for (int i = n; i >= 1; i--) {
			vec.emplace_back(i);
		}
		for (int i = 0; i < r; i++) {
			cin >> p >> c;
			for (int j = 0; j < c; j++) {
				vec.insert(vec.begin(),(vec[p + c - 2]));
				vec.pop_back();
			}
		}
		cout << vec[0] << endl;
	}
}

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

int main()
{
    int n, r = 0;
    int p, c = 0;
    while (std::cin >> n >> r && n > 0) {
        std::vector<int> v(n);
        for (int i = 0; i < n; i++) {
            v.at(n - i - 1) = i + 1;
        }
        for (int i = 0; i < r; i++) {
            std::cin >> p >> c;
            std::rotate(v.begin(), v.begin() + p - 1, v.begin() + p + c - 1);
        }
        std::cout << v.at(0) << '\n';
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <stack>

using namespace std;


int main(){

	int n, r;

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

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

		int p, c;
		for(int i=0 ; i<r ; i++){
			cin >> p >> c;
			for(int j=0 ; j<c ; j++){
				temp[j] = a[p-1+j];
			}
			for(int j=0 ; j<p-1 ; j++){
				temp[c+j] = a[j];
			}
			for(int j=c+p-1 ; j<n ; j++){
				temp[j] = a[j];
			}

			for(int j=0 ; j<n ; j++){
				a[j] = temp[j];
			}
		}
		cout << a[0] << endl;

	}

	return 0;
}