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>
using namespace std;
int main(){
  int a[51]={};
  int st[51]={};
  int n,r;
  int p,c;
  while(1){
    //in
    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<n;j++){
	st[j]=a[j];
      }
      for(int j=0;j<c;j++){
	a[j]=st[p+j-1];
      }
      for(int j=0;j<p-1;j++){
	a[j+c]=st[j];
      }
    }
    cout << a[0] << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        int n, r;
        cin >> n >> r;
        if(n == r && r == 0) break;
        int p[55];
        int c[55];
        for(int i = 1; i <= r; i++) cin >> p[i] >> c[i];
        int pos = 1;
        for(int i = r; i >= 1; i--) {
            if(pos > c[i] + p[i] - 1) continue;
            if(pos <= c[i]) {
                pos += p[i] - 1;
                continue;
            }
            pos -= c[i];
        }
        cout << n + 1 - pos << endl;
    }
    return 0;
}

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

using namespace std;

int main(int argc, char const* argv[])
{
	int n, r, p, c;

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

		std::vector<int> cards(n);

		for(int i = 0; i < n; ++i) {
			cards.at(n - i - 1) = i + 1;
		}

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

			std::vector<int> temp_p;
			std::vector<int> temp_c;

			std::copy_n(cards.begin(), p - 1, std::back_inserter(temp_p));
			std::copy_n(cards.begin() + p - 1, c, std::back_inserter(temp_c));

			std::copy(temp_c.begin(), temp_c.end(), cards.begin());
			std::copy(temp_p.begin(), temp_p.end(), cards.begin() + c);
		}

		std::cout << cards.at(0) << std::endl;
	}

	return 0;
}

C++: //19
#include<iostream>
#include<cstring>

using namespace std;

int main(){
  for(int n,r;cin>>n>>r,n|r;){
    int card[50];
    for(int i=0;i<n;i++){
      card[i]=n-i;
    }
    for(int i=0;i<r;i++){
      int p,c;
      cin>>p>>c;
      int temp[50];
      memcpy(temp,card,sizeof(card[0])*(p-1));
      memmove(card,card+p-1,sizeof(card[0])*c);
      memcpy(card+c,temp,sizeof(card[0])*(p-1));
    }
    cout<<card[0]<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int main()
{
    int n, r, p[64], c[64];
    while (scanf("%d%d", &n, &r), n | r)
    {
	for (int i = 0; i < r; ++i)
	    scanf("%d%d", p + i, c + i);

	int pos = 1;
	for (int i = r - 1; i >= 0; --i)
	{
	    if (pos <= c[i])
		pos += p[i] - 1;
	    else if (pos <= c[i] + p[i] - 1)
		pos -= c[i];
	}
	printf("%d\n", n - (pos - 1));
    }
}

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

using namespace std;
int n, r, p, c;

int main(){
	while (cin >> n >> r && n){
		int a[55];
		for (int i = 0; i < r; i++){
			a[i] = i + 1;
		}
		for (int j = 0; j < r; j++){
			cin >> p >> c;
			rotate(a + n - p - c + 1, a + n - p + 1, a + n);
		}
		cout << a[n - 1] << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
        int n,r;
        cin >> n >> r; 
        while(n){
                int in[50][2];
                for(int i = 0; i < r; i++){
                        cin >> in[i][0] >> in[i][1];
                }  
                int m = n; 
                for(int i = r-1; i >= 0; i--){
                        int p = in[i][0];
                        int c = in[i][1];
                        if(n-p-c+1 > m) continue;
                        if(n-c < m){
                                m -= p-1;
                        }else{
                                m += c; 
                        }  
                }  
                cout << m << endl;
                cin >> n >> r; 
        }  
}

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

	}
	return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>

#pragma warning( disable: 4996 )

using namespace std;

typedef long long ll;

#define INF 100000000
#define EPS 1e-9

#define MAX_N 50
#define MAX_R 50

int n, r;
int p[MAX_R];
int c[MAX_R];
vector<int> ans_list;

int main(){
	
	while (true){
	
		cin >> n >> r;

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

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

		int ans[MAX_N];
		for (int i = 0; i < n; i++){
			ans[i] = n - i;
		}
		int tmp[MAX_N];

		for (int i = 0; i < r; i++){
			
			for (int j = 0; j < c[i]; j++){
				tmp[j] = ans[p[i] - 1 + j];
			}

			for (int j = p[i]-2; j >= 0; j--){
				ans[j + c[i]] = ans[j];
			}

			for (int j = 0; j < c[i]; j++){
				ans[j] = tmp[j];
			}

		}

		ans_list.push_back(ans[0]);
	
	}

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


	return 0;

}

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

int main()
{
	int n, r;
	while (scanf("%d %d", &n, &r), n + r){
		vector<int> a;
		for (int i = n; i >= 1; i--){
			a.PB(i);
		}
		for (int i = 0; i < r; i++){
			int p, c;
			scanf("%d %d", &p, &c);
			vector<int> b;
			for (int i = p - 1; i < p + c - 1; i++){
				b.PB(a[i]);
			}
			for (int i = 0; i < p - 1; i++){
				b.PB(a[i]);
			}
			for (int i = p + c - 1; i < n; i++){
				b.PB(a[i]);
			}
			a = b;
		}
		printf("%d\n", a[0]);
	}
	
	return 0;
}