Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		n, _ := strconv.Atoi(chunks[0])
		r, _ := strconv.Atoi(chunks[1])
		cards := make([]int, n, n)
		for i := 0; i < n; i++ {
			cards[i] = n - i
		}
		for i := 0; i < r; i++ {
			sc.Scan()
			chunks := strings.Split(sc.Text(), " ")
			p, _ := strconv.Atoi(chunks[0])
			c, _ := strconv.Atoi(chunks[1])
			block := make([]int, c, c)
			for j := 0; j < c; j++ {
				block[j] = cards[p+j-1]
			}
			for j := p - 2; j >= 0; j-- {
				cards[j+c] = cards[j]
			}
			for j := 0; j < c; j++ {
				cards[j] = block[j]
			}
		}
		fmt.Println(cards[0])
	}
}

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

int n, r, p, c, d[50], e[50];

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

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

using namespace std;

int main( void ){
	vector< int > result;
	deque< int > card;
	while( true ){
		int n, r;
		cin >> n >> r;
		if( n == 0 && r == 0 )
			break;
		for( int i = 1; i < n + 1; i++ ){
			card.push_front( i );
		}
		for( int i = 0; i < r; i++ ){
			int p, c;
			cin >> p >> c;
			for( auto itr = card.begin(); itr != card.end(); ++itr ){
				if( ( *itr ) =< p ){
					int temp = ( *itr );
					card.erase( itr );
					card.push_front( temp );
				}
			}
		}

		result.push_back( card.front() );
			
	}

	for( auto itr = result.begin(); itr != result.end(); ++itr ){
		cout << ( *itr ) << endl;
	}

	return 0;
}

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

int main()
{
  while(1){
    int n, r;
    cin >> n >> r;
    if(n == 0 && r == 0){
      break;
    }else{
      stack <int> x, y, z;
      while(!x.empty())
	x.pop();
      for(int i = 1; i <= n; i++)
	x.push(i);
      for(int i = 0; i < r; i++){
	int p, c;
	cin >> p >> c;
	for(int j = 1; j < p; j++){
	  y.push(x.top());
	  x.pop();
	}
	for(int j = 0; j < c; j++){
	  z.push(x.top());
	  x.pop();
	}
	while(!y.empty()){
	  x.push(y.top());
	  y.pop();
	}
	while(!z.empty()){
	  x.push(z.top());
	  z.pop();
	}
      }
      cout << x.top() << endl;
    }
  }
}

C++: #include<iostream>

using namespace std;

int main(){

   while(1){

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

      cout<< a[0]<< endl;
   }
   return 0;
}

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){
    //?±±??????????????????                                                            
    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];
  }
  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);
  }
}

C++: #include <iostream>
using namespace std;
 
int n, r, p, c;
int cards[64];
 
void init() {
    for(int i = 0; i < n; i++)
        cards[i] = n - i;
}
 
bool input() {
    cin >> n >> r;
    if(!n && !r)
        return false;
    return true;
}
 
void shuffle() {
    int tmp[64];
    
    // c 個分の要素をtmpに格納
    for(int i = 0; i < c; i++)
        tmp[i] = cards[p - 1 + i];
    // p-1 個分の要素を c 個分ずらす
    for(int i = 0; i < p - 1; i++)
        cards[p - 2 - i + c] = cards[p - 2 - i];
    // 先頭に c 個分の要素をつめる
    for(int i = 0; i < c; i++)
        cards[i] = tmp[i];
}
 
int solve() {
    for(int i = 0; i < r; i++) {
        cin >> p >> c;
        shuffle();
    }
    return cards[0];
}
 
int main() {
    while(input()) {
        init();
        cout << solve() << endl;
    }
    return 0;
}

C++: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//V,P(大文字)使用不可

const ll INF=1e18;

V<int> b[55];

V<int> f(V<int> a,int p,int c,int n){
    V<int> b;
    for(int i=p-1;i<p-1+c;i++){
        b.push_back(a[i]);
    }
    for(int i=0;i<p-1;i++) b.push_back(a[i]);
    for(int i=p-1+c;i<n;i++) b.push_back(a[i]);
    return b;
}

signed main(){
    while(true){
        int n,r;
        cin>>n>>r;
        if(n==0&&r==0) break;
        V<int> a,ans;
        for(int i=n;i>0;i--) a.push_back(i);
        for(int i=1;i<=r;i++){
            int p,c;
            cin>>p>>c;
            if(i==1) b[i]=f(a,p,c,n);
            else b[i]=f(b[i-1],p,c,n);
        }
        cout<<b[r][0]<<endl;
    }
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
  
int main()
{
	int n,m;
	int p[51]={0};
	int c[51]={0};
	int i;
	int ans;

	while(1)
	{
	scanf("%d %d",&n,&m);
	if((n==0)&&(m==0))
		break;
	ans=n;

	for(i=1;i<=m;i++){
		scanf("%d %d",&p[i],&c[i]);	
	} 

	for(i=m;i>=1;i--){
		if(p[i]!=1){
		if((n-p[i]-c[i]+1)>=ans){
		}else if(ans>=(n-c[i]+1)){
			ans = ans-p[i]+1;
		}else
			ans = ans+c[i];
		}
	}

	printf("%d\n",ans);

	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<long long,int> P;
static const int INF=1<<24;

int a[50];

int main(){
	int n,r;
	while(cin>>n>>r,!(n==0&&r==0)){
		rep(i,n+1){
			a[i]=n-i;
		}
		int p,c;
		int t1[50]={0},t2[50]={0};
		
		rep(i,r){
			cin>>p>>c;
			for(int j=0;j<c;j++){
				t1[j]=a[j+p-1];
				//cout<<t1[j]<<endl;
			}
			//cout<<endl;
			for(int j=0;j<p-1;j++){
				t2[j]=a[j];
			}
			for(int j=0;j<c;j++){
				a[j]=t1[j];
			}
			for(int j=0;j<p-1;j++){
				a[j+c]=t2[j];
			}
			/*
			rep(j,n){
				cout<<a[j]<<" ";
			}
			cout<<endl;
			*/
		}
		cout<<a[0]<<endl;
	}
	return 0;
}