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 all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int n, r;
vector<int> p, c;
void ops(vector<int> &card, int p, int c) {
    auto tmp = card;
    p--;
    rep(i, p) {
        card[i + c] = tmp[i];
    }
    rep(i, c) {
        card[i] = tmp[i + p];
    }
}
void solve() {
    vector<int> card(n);
    rep(i, n) card[i] = n - i;
    rep(i, n) cout << card[i] << " ";
    cout << endl;
    rep(i, r) {
        ops(card, p[i], c[i]);
        // rep(i, n) cout << card[i] << " ";
        // cout << endl;
    }
    cout << card[0] << endl;
}
int main() {
    while (cin >> n >> r, n) {
        p.resize(r);
        c.resize(r);
        rep(i, r) cin >> p[i] >> c[i];
        solve();
    }

    return 0;
}

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

int main() {
	int n, r;
	while( cin >> n >> r, n&&r ) {
		vector<int>N( n ), M, L;
		iota( N.begin(), N.end(), 1 );
		for( size_t i = 0; i < r; i++ ) {
			int a, b;
			cin >> a >> b;
			a--;
			for( size_t j = 0; j < a; j++ ) {
				M.push_back( *N.rbegin() );
				N.pop_back();
			}
			for( size_t j = 0; j < b; j++ ) {
				L.push_back( *N.rbegin() );
				N.pop_back();
			}
			for( size_t j = 0; j < a; j++ ) {
				N.push_back( *M.rbegin() );
				M.pop_back();
			}
			for( size_t j = 0; j < b; j++ ) {
				N.push_back( *L.rbegin() );
				L.pop_back();
			}
		}
		cout << *N.rbegin() << endl;
	}
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main()
{
	while (true)
	{
		int n, r;
		cin >> n >> r;
		if (!n && !r)
			break;
		stack<int> S;
		stack<int> s1;
		stack<int> s2;
		for (int i = 1; i <= n; i++)
			S.push(i);
		for (int i = 1; i <= r; i++)
		{
			int p, c;
			cin >> p >> c;
			for (int i = 1; i <= p - 1; i++)
			{
				int t = S.top();
				S.pop();
				s1.push(t);
			}
			for (int i = 1; i <= c; i++)
			{
				int t = S.top();
				S.pop();
				s2.push(t);
			}
			for (int i = 1; i <= p - 1; i++)
			{
				int t = s1.top();
				s1.pop();
				S.push(t);
			}
			for (int i = 1; i <= c; i++)
			{
				int t = s2.top();
				s2.pop();
				S.push(t);
			}
		}
		cout << S.top() << endl;
	}
}

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

//?±±?????????????????¢??°???????±±???????±±????????°n???p?????????????????????c???                       
void shuffle(vector<int> &yama, int n, int p, int c);


int main(){
  int n, r;
  int p, c;
  vector<int> yama, v;

  cin >> n;
  cin >> r;

  while(n != 0 && r != 0){
    //?±±??????????????????                                                            
    yama.clear();
    for(int i = 0, j = n; i < n; i++, j--){
      yama.push_back(j);
    }
    //?????£?????????                                                                
    for (int i = 0; i < r; i++){
      cin >> p;
      cin >> c;
      shuffle(yama, n, p, c);
    }
    //???????????????????¨????                                                          
    v.push_back(yama.front());

    cin >> n;
    cin >> r;
  }
  for(int i = 0; i < v.size(); i++){
    cout << v[i] << endl;
  }
  cout << endl;
}
void shuffle(vector<int> &yama, int n, int p, int c){
  int tmp;

  for(int i = 0;i < c; i++){
    tmp = yama[p-1+c-1];
    yama.erase(yama.begin()+p-1+c-1);
    yama.insert(yama.begin(), tmp);
    for(int j = 0; j < yama.size(); j++){
      cout << yama[j] << " ";
    }
    cout << endl;

  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,r;
  while(cin >> n >> r,n){
    vector<int> a(n);
    for(int i=0; i<n; i++) a[i] = n-i;

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

      vector<int> v1,v2;
      for(int j=0; j<p-1; j++) v1.push_back(a[j]);
      for(int j=0; j<c; j++) v2.push_back(a[j+p-1]);
      for(int j=0; j<c; j++) a[j] = v2[j];
      for(int j=0; j<p-1; j++) a[j+c] = v1[j];
    }
    cout << a[0] << endl;
  }
  return 0;
}

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-1+j];
      }
      for(int j=c;j<c+p;j++){
	a[j]=st[j-c];
      }
    }
    cout << a[0] << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
int main(void)
{
	int n, r, p, c;
	int num[1000][50];
	int ans[1000];
	int i, t,k,l;
	int change;
	int re[1000];
	n = r = 1;
	for (i = 0; i < 1000; i++)
	{
	scanf("%d %d", &n, &r);
	if (n == 0 && r == 0)
	{
		break;
	}
	for (t = 0; t < n; t++)
	{
		num[i][t] = n - t;
	}
	for (t = 0; t < r; t++)
	{
	
		scanf("%d %d", &p, &c);
		for (l = 0; l < n ; l++)
		{
			re[l] = num[i][l];
		}
		for (k = 0; k < c; k++)
		{
			change = re[p-1+k];
			num[i][k] = change;
		}
		for (k = 0; k < p - 1; k++)
		{
			change = re[k];
			num[i][c + k] = change;
		}
			
	}
	ans[i] = num[i][0];
	}
	for (t = 0; t < i; t++)
	{
		printf("%d\n", ans[t]);
	}

	
}

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

int main()
{

  int n, r, p, c;
  
 while(cin >> n >> r, n){
        int s[n];
	
        for(int i = 0; i < n; i++){   // s??????????????????????????\??????
            s[i] = n - i;
        }
	
        for(int i = 0; i < r; i++){
       
            cin >> p >> c;
            rotate(s, s + p - 1, s + p + c - 1);	    
        }
	
        cout << s[0] << endl;
    }

}

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

int main(){

  while(1){

    int n, p, c, r, yamahuda[51] = {0}, ue[51] = {0}, shita[51] = {0}, cnt = 1;

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

    for(int i = n; i >= 1; i--){
      yamahuda[n-i+1] = i;
    }

    for(int i = 1; i <= r; i++){
      cin >> p >> c;
      for(int j = 1; j < p; j++){
	ue[j] = yamahuda[j];
	//cout << ue[j];
      }
      //cout << endl;
      cnt = 1;
      for(int s = p; s < p+c; s++){
	shita[cnt] = yamahuda[s];
	//	cout << shita[cnt];
	//cout << cnt;
	cnt++;
      }
      //cout << endl;
      // cnt = 1;
      for(int l = 1; l < cnt; l++){
	yamahuda[l] = shita[l];
	//	cout << shita[l];
      }
      //  cout << endl;
      
      for(int m = 1; m < p; m++){
	yamahuda[cnt] = ue[m];
	cnt++;
      }
      // for(int k = 1; k <= n; k++) cout << yamahuda[k];
      //cout << endl;
    }
     cout << yamahuda[1] << endl;
   
    
  }

  return 0;
}

C++: #include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
using namespace std;

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

vector<int> ans;
vector<int> col;



void changeCol(int p,int c){
    vector<int> toDOWN;
    vector<int> toUP;

    for (int i = 1; i <= p-1; i++)toDOWN.push_back(col[i]);
    for (int i = p; i <= p+c-1; i++)toUP.push_back(col[i]);

    for(int i=1;i<=c;i++)col[i]=toUP[i-1];
    for(int i=c+1,j=0;i<p+c;i++,j++)col[i]=toDOWN[j];
}


int main(){
int n,r;
int tmp1,tmp2;
    while(1){
        cin>>n>>r;
        if(n==0&&r==0)break;
        col.clear();
        for(int i=0;i<=n;i++)col.push_back(i);
        for (int j = 0; j < r; j++){
            cin>>tmp1>>tmp2;
            changeCol(tmp1,tmp2);
        }
        ans.push_back(n+1-col[1]);
    }
     for(int i=0;i<ans.size();i++){
        cout<<ans[i]<<"\n";
    }
    return 0;
}