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>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
#define INF 10000000000000000
#define MOD 998244353
using namespace std;

int main(){
    while(true){
        
        stack<int> s;
        int n,r;
        cin >> n >> r;
        
        if(n==0 && r==0){break;}
        
        for(int i=0; i<n; i++){
            s.push(i+1);
        }

        for(int i=0; i<r; i++){
            int p,c;
            cin >> p >> c;
            
            
            stack<int> a;
            stack<int> b;
            
            for(int i=0; i<p-1; i++){
                a.push(s.top());
                s.pop();
            }
            for(int i=0; i<c; i++){
                b.push(s.top());
                s.pop();
            }
            
            while(!a.empty()){
                s.push(a.top());
                a.pop();
            }
            
            while(!b.empty()){
                s.push(b.top());
                b.pop();
            }
        }
        
        cout<<s.top()<<endl;
    }
    
    return 0;
}

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

using namespace std;

vector<int>card;

void cut(int p,int c){
  vector<int>res;
  for(int i=p;i<p+c;i++)res.push_back(card[i]);
  for(int i=0;i<p;i++)res.push_back(card[i]);
  for(int i=p+c;i<card.size();i++)res.push_back(card[i]);
  card=res;
}

int main(void){
  int n,r;

  while(cin >> n >> r, n|r){
    card.resize(n);
    for(int i=0;i<n;i++)card[i]=n-i;
    
    int p,c;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      cut(p-1,c);
    }
    cout << card[0] << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int n,m,p,q,r;
struct cards
{
    int from,to;
    cards(int f,int t)
    {
        from=f,to=t;
    }
};
deque<cards> all;
deque<cards> split(int k)
{
    deque<cards> sub;
    for(;;)
    {
        cards t=all.front();
        all.pop_front();
        k -= t.to-t.from+1;
        if(k==0)
        {
            sub.pb(t);
            break;
        }
        if(k<0)
        {
            all.push_front(cards(t.to+k+1,t.to));
            t.to+=k;
            sub.pb(t);
            break;
        }
        sub.pb(t);
    }
    return sub;
}
void shuffle(int x,int y)
{
    deque<cards> a=split(x);
    deque<cards> b=split(y);
    for(int i=0;i<a.size();i++)all.push_front(a[i]);
    for(int i=0;i<b.size();i++)all.push_front(b[i]);
}
int main()
{
    while(1)
    {
        cin >> n >> m;
        if(n==0&&m==0)break;
        all.clear();
        all.pb(cards(1,n));
        for(int i=0;i<m;i++)
        {
            int p,c;
            cin >> p >> c;
            shuffle(p-1,c);
        }
        cout << n-all[0].from+1 << endl;
    }
    return 0;
}

C++: 
#include <iostream>

using namespace std;

int main()
{
    int yama[51], tmp[51];

    int n, r;
    while (cin >> n >> r, (n || r))
    {
        for (int i = 0; i < n; i++)
        {
            yama[i] = i + 1;
        }

        for (int i = 0; i < r; i++)
        {
            int p, c;
            cin >> p >> c;
            for (int j = 0; j < c; j++)
            {
                tmp[c - 1 - j] = yama[n - p - j];
            }
            for (int j = n - p + 1; j < n; j++)
            {
                yama[j - c] = yama[j];
            }
            for (int j = 0; j < c; j++)
            {
                yama[n - c + j] = tmp[j];
            }
        }

        cout << yama[n - 1] << endl;
    }
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cctype>

using namespace std;

#define REP(i,n) for(int i = 0;i < n;i++)
	
int main()
{
	int n,r;
	while(cin >> n >> r,n)
	{
		vector<int> v;
		REP(i,n)
		{
			v.push_back(i+1);
		}
		REP(i,r)
		{
			int p,c;
			cin >> p >> c;
			vector<int> tmp;
			REP(j,c)
			{
				tmp.push_back(v[v.size()-p-j]);
			}
			v.erase(v.end()-p-c+1,v.end()-p+1);
			REP(j,c)
			{
				v.push_back(tmp[tmp.size()-j-1]);
			}
		}
		
		cout << v.back() << endl;
		
	}
	
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define REP(i,k,n) for(int i = k; i < n; i++)

#define vi vector<int>
#define pb push_back
using namespace std;

int main(){
    int n,r;
    while(cin >> n >> r,n) {
        vi card(n);
        rep(i,n) card[i] = n - i;
        rep(i,r){
            int p,c;
            cin >> p >> c;
            vi tmp(c);
            rep(j,c) tmp[j] = card[p - 1 + j];
            rrep(j,p - 1) card[j + c - 1] = card[j];
            rep(j,c) card[j] = tmp[j];
        }
        cout << card[0] << endl;
    }
    return 0;

}

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

using namespace std;

int main() {
  int n, r;
  cin >> n >> r;

  if (!n) return 0;

  vector<int> ary;
  for (int i = n; i >= 1; i--) {
    ary.push_back(i);
  }
  for (int i = 0; i < r; i++) {
    vector<int> tmp;
    int p, c;
    cin >> p >> c;
    for (int j = 0; j < c; j++) {
      tmp.push_back(ary[p - 1 + j]);
    }
    for (int j = p - 2; j >= 0; j--) {
      ary[j + c] = ary[j];
    }
    ary = tmp;
    tmp.clear();
  }
  cout << ary[0] << endl;

  main(); // kikaku ihan dakedo
}

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


using namespace std;
int main()
{
    int n,r;
    while(cin>>n>r){
        
        if(n==0&&r==0)break;
        stack<int> st1;
        for(int i=0; i<n; i++){
            st1.push(i+1);
        }
        
        for(int rop=0; rop<r; rop++){
            int p,c;
            cin>>p>>c;
            stack<int> st2,st3;
            for(int i=0; i<p-1; i++){
                st2.push(st1.top());
                st1.pop();
            }
            
            for(int i=0; i<c; i++){
                st3.push(st1.top());
                st1.pop();
            }
            
            while (!st2.empty()) {
                st1.push(st2.top());
                st2.pop();
            }
            
            while (!st3.empty()) {
                st1.push(st3.top());
                st3.pop();
            }
        }
        
        cout<<st1.top()<<endl;
    }
}