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 <stdio.h>

int main(){
    int n,r,i,j,p,c,a[51],b[51];
    while(1){
        scanf("%d %d",&n,&r);
        if (n==0&&r==0) break;
        for (i=1;i<=n;i++) {
            a[i]=i; //a[i]????????????i??????????????????????????????????????????
        }
        for (i=0;i<r;i++) {
            scanf("%d %d",&p,&c);
            for (j=1;j<=c;j++) {
                b[j]=a[j];
                a[j]=a[j+p-1];
            }
            if (p-1>c) {
                for (j=c+1;j<p;j++) {
                    b[j]=a[j];
                }
            }
            for (j=1;j<p;j++) {
                a[j+c]=b[j];
            }
        }
        printf("%d\n",a[1]);
        
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        pair<int, int> n; cin >> n.first >> n.second;
        if(n.first == 0 and n.second == 0) return 0;
        else{
            vector<int> Card(n.first);
            int tmp = n.first;
            for(int i = 0; i < n.first; i++){
                Card[i] = tmp;
                tmp--;
            }
            REP(i, n.second){
                pair<int, int> cut; cin >> cut.first >> cut.second;
                vector<int> New(0);
                for(int i = cut.first - 1; i < cut.first + cut.second - 1; i++) New.push_back(Card[i]);
                REP(i, cut.first - 1) New.push_back(Card[i]);
                FOR(i, cut.first + cut.second - 1, n.first) New.push_back(Card[i]);
                REP(i, n.first) Card[i] = New[i];
            }
            cout << Card[0] << endl;
        }
    }
}

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;
		}
	    //cout<<a[0]<<a[1]<<a[2]<<a[3]<<a[4]<<endl;
		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;j++)
			{
				b[c+j]=a[j];
			}
			for(j=0;j<p+c;j++)
			{
				a[j]=b[j];
			}
			i++;
			//cout<<a[0]<<a[1]<<a[2]<<a[3]<<a[4]<<endl;
		}
		cout<<a[0]<<endl;

	}
	return 0;
}

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

int main()
{
	int n,r,p,c;
	int x[64],t[64];
	while(cin >> n >> r, n||r)
	{
		for(int i=0; i<n; i++)
		{
			x[i]=n-i;
		}

		while(r--)
		{
			cin >> p >> c;
			for(int i=0; i<p-1; i++)
			{
				t[i] = x[i];
			}
			for(int i=0; i<c; i++)
			{
				x[i] = x[p-1+i];
			}
			for(int i=0; i<p-1; i++)
			{
				x[c+i] = t[i];
			}
		}
		cout << x[0] << endl;

	}
}

C++: 
#include <stdio.h>
int main(){
  int n,r,p,c,i,j,k,nh[51],s[51];
  while(1){
    scanf("%d%d",&n,&r);
    if(n==0&&r==0) break;

    for(i=n;i>=1;i--){
      nh[n-i+1]=i;
    }
 
    for(i=0;i<r;i++){
      scanf("%d%d",&p,&c);
      for(j=p;j<=p+c-1;j++){
        s[j]=nh[j];
      }
      for(j=1;j<=c;j++){
	for(k=p-1;k>=1;k--){
          nh[k+1]=nh[k];
	}
      }
    
      for(j=p;j<=p+c-1;j++){
        nh[j-p+1]=s[j];
      }
    }

    printf("%d\n",nh[1]);
  }
    return 0;
}

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

int main() {
  for(int n, r; cin >> n >> r && (n|r); ){
    deque<int> deq;
    for(int i = 0; i < n; ++i) deq.push_front(i+1);
    for(int i = 0; i < r; ++i) {
      int p, c;
      cin >> p >> c;
      --p;
      deque<int> tmp(deq.begin() + p, deq.begin() + (p+c));
      deq.erase(deq.begin() + p, deq.begin() + (p+c));
      for(int j = (int)tmp.size()-1; j >= 0; --j) deq.push_front(tmp[j]);
    }
    cout << deq.front() << endl;
  }
  return 0;
}

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

using namespace std;

int top_search(int,int,int,int *);
int main(){
	int n,r,c,p;
	int cnt=0;
	int top[51];
	while(1){
		cin>>n>>r;
		if(n==0&&r==0)
			break;
		int *hanahuda=new int[n];

		for (int i = n-1; i>=0 ; i--)
			hanahuda[i]=n-i;

		for(int i=0;i<r;i++){
			cin>>p>>c;
			top[cnt]=top_search(n,p,c,hanahuda);
		}
		delete[] hanahuda;
		cnt++;
	}
	for(int m=0;m<cnt;m++)
		cout<<top[m]<<endl;
	return 0;
}
int top_search(int n,int p,int c,int *hanahuda){
	int cnt=0;
	for(int k=p-1;k<p+c-1;k++){

		int nokori=hanahuda[k];

		for(int l=p-2;l>=0;l--)
			hanahuda[l+1]=hanahuda[l];


		hanahuda[cnt]=nokori;
		cnt++;
	}

	return *hanahuda;
}

C++: #include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;

int main(){
	int n,r;
	while(cin>>n>>r&&n){
		stack<int> st,tmp1,tmp2;
		int p,c;
		REP(i,1,n+1){
			st.push(i);
		}
		REP(i,0,r){
			cin>>p>>c;
			REP(j,0,p-1){
				tmp1.push(st.top());
				st.pop();
			}
			REP(j,0,c){
				tmp2.push(st.top());
				st.pop();
			}
			while(!tmp1.empty()){
				st.push(tmp1.top());
				tmp1.pop();
			}
			while(!tmp2.empty()){
				st.push(tmp2.top());
				tmp2.pop();
			}
		}
		p(st.top());
	}

	return 0;
}