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 <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i=0;i<n;++i)
#define Rep(i,n) for(int i=1;i<=n;++i)
#define rrep(i,n) for(int i=n-1;0<=i;--i)
#define rRep(i,n) for(int i=n;0<i;--i)
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define scani(a) scanf("%d",&a)
#define scanr(a) scanf("%lf",&a)
#define scans(s) scanf("%s",s)
#define printi(a) printf("%d",a)
#define printr(a) printf("%lf",a)
#define prints(s) printf("%s",s)
#define is_odd(n) (n&1)
#define is_even(n) ((n+1)&1)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
#define all(x) x.begin(), x.end()
#define EPS 1e-8
#define INF 1e8
#define PI acos(-1.0)

typedef double Real;
typedef int Int;
typedef vector<Int> vi;
typedef vector<vector<Int> > vvi;
typedef pair<Int,Int> pii;

inline Real sr(Real a) {return sqrt(max(a, (Real)0));}
template <typename T> inline T sq(T a) {return a * a;}
const vi dy = {-1, 0, 1, 0}, dx = {0, -1, 0, 1};
vector<string> split(const string &s, char d) {vector<string> r;stringstream t(s);string x;while(getline(t,x,d))if(!x.empty())r.push_back(x);return r;}

void solve()
{
  for(;;)
  {
    Int n, r; scani(n); scani(r);
    if(n == 0 && r == 0) break;

    Int deck[n], buf[n];
    rep(i, n) deck[i] = n-i;

    rep(i, r)
    {
      Int p, c; scani(p); scani(c);

      copy(deck, deck+p+c-1, buf);
      copy(buf+p-1, buf+p+c-1, deck);
      copy(buf, buf+p-1, deck+c);
    }

    cout << *deck << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(9);

  solve();

  return 0;
}

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

int main() {
    int n, r;
    while(cin >> n >> r) {
        if(n == 0 && r == 0) break;
        vector<int> array(51); for(int i=0; i<n; i++) array[i] = n-i;
        vector<int> temp(51);
        for(int i=0; i<r; i++) {
            int a, b;
            cin >> a >> b;
            a--;
            
            int x = 0, y = b;
            for(int j=0; j<n; j++) {
               if(j < a || a + b - 1 < j) {
                   temp[y] = array[j];
                   y++;
               }
               else {temp[x] = array[j]; x++;}
            }
            
            for(int j=0; j<n; j++) array[j] = temp[j];
            // for(int j=0; j<n; j++) cout << array[j] << " ";
            // cout << endl;
        }
        cout << array[0] << endl;
    }
    return 0;
}

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

int main() {
	int n,r;
	int p,c;
	while(1)
	{
		cin>>n>>r;
		if(n==0||r==0)
		{
			break;
		}
		int i=1;
		int a[n];
		int b[n];
		for(i=0;i<n;i++)
		{
			a[i]=n-i;
			b[i]=0;
		}
		i=0;
		while(r!=i)
		{
			cin>>p>>c;
			int j;
			for(j=0;j<c;j++)
			{
				b[j]=a[j+(p-1)];
			}
			for(j=0;j<p-1;j++)
			{
				b[c+j]=a[j];
			}
			for(j=0;j<p+c;j++)
			{
				a[j]=b[j];
			}
			i++;
		}
		cout<<a[0]<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <array>

using namespace std;

int main(){
    int A[50];
    int n,m,p,c;
    while(true){
        cin >> n >> m;
        if(n+m == 0)break;
        for(int i = 0;i < n;i++)A[i] = n - i;
        for(int i = 0;i < m;i++){
            cin >> p >> c;
            rotate(A,A+p-1,A+p+c-1);
//            for(int k = 0;k < n;k++){
//                cout << A[k] << " ";
//            }
//            cout << endl;
        }
        cout << A[0] << endl;
    }
}

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

int n,r;

int main(){

	while(1){
    cin >> n >> r;
    if ((n == 0)&&(r == 0)){
          break;
		}
	int A[n];
	for (int i = 0; i <= n-1; i++){
		A[i] = n-i;
		//cout << A[i] << endl;
	}
	int p,c;


for (int i = r; i >=1; i--){

		cin >> p >> c;

		int M[p-1];
		int N[c];
		for (int i = 0; i <= p-2; i++){
			M[i] = A[i];
		}
		for (int i = 0; i <= c-1; i++){
			N[i] = A[p-1+i];
		}
		//??????
???????????????for (int i = 0; i <= c-1; i++){
			A[i]  = N[i];
		}
		for (int i = 0; i <= p-2; i++){
			A[c+i]  = M[i];
		}
		if(i == 1){
			cout << A[0] << endl;
		}

	}
  }
}

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

struct order {
	int p, c;
};

int main()
{
	int n, r, p;
	vector<order> o;
	order t;
	
	while (cin >> n >> r, n | r) {
		o.clear();
		p = 1;
		
		for (int i = 0; i < r; i++) {
			cin >> t.p >> t.c;
			o.push_back(t);
		}
		
		for (int i = o.size() - 1; i >= 0; i--) {
			if (p <= o[i].c) {
				p += o[i].p - 1;
			} else if (p - o[i].c <= o[i].p - 1) {
				p = p - o[i].c;
			}
		}
		
		cout << n - p + 1 << endl;
	}
	
	return 0;
}

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

int main(void)
{
    int n,r,p,c;
    while(1) {
        cin >> n >> r;
        if(n==0 && r==0) break;
        int a[n],b[n];
        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++)
                b[j] = a[j];
            for(int j=0; j<p-1; j++)
                b[j+c] = a[j];
            for(int j=0; j<c; j++)
                b[j] = a[j+(p-1)];
            for(int j=0; j<n; j++)
                a[j] = b[j];
        }
        cout << a[0] << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <functional>

using namespace std;

int INF = 10000000;

int n , r;
int N[50];


int main()
{

	while(cin >> n >> r && n && r)
	{

		for(int i = 0;i < n;i++)N[i] = n-i-1;

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

			int temp[50];
			int t = 0;

			for(int j = p;j < p+c;j++)
			{
				temp[t++] = N[j];
			}
			t = p-1;

			for(int j = p+c-1;j >= 0;j--)
			{
				if(t>=0)N[j] = N[t--];
			}

			for(int j = 0;j < c;j++)
			{
				N[j] = temp[j];
			}
		}

		cout << N[0]+1 << endl;



	}

  return 0;
}