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 <vector>
using namespace std;

int main()
{
	int n, r, p, c;
	while (true) {
		cin >> n >> r;

		if (n == 0 && r == 0) {
			break;
		}

		vector<int> cards;
		for (int i = 1; i <= n; i++) {
			cards.push_back(i);
		}

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

			p = n - p - c + 1;
			for (int j = 0; j < c; j++) {
				cards.push_back(cards[p]);
				cards.erase(cards.begin() + p);
			}
		}

		cout << cards.back() << '\n';
	}

	return 0;
}

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

#define first  fs
#define second se
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, char s = '\n') { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	int n, r;
	while (cin >> n >> r, n) {
		vi v;
		rep(i, n) v.push_back(n - i);

		rep(_, r) {
			int p = in(), c = in();
			vi beet, ei;
			for (int i = p - 1; i < p + c - 1; ++i) beet.push_back(v[i]);
			rep(i, p - 1) beet.push_back(v[i]);

			rep(i, beet.size()) v[i] = beet[i];
		}

		print(v[0]);
	}
}

C++: #include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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


const ll MOD=1e9+7;
const ll INF=1e18;

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

int  card[60];
int tmp[60];
int p,c;

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

	}
}

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

int main(void){
  while(1){
    int n, r;
    cin >> n;
    cin >> r;
    if(n == 0 && r == 0){return 0;}

    int f[n];
    for(int i = 0 ; i < n ; i++){
      f[i] = n - i;
    }

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


    for(int i = 0 ; i < r ; i++){
      int tempu[p[i]-1];
      int tempd[c[i]];
      for(int j = 0 ; j < p[i]-1 ; j++){
        tempu[j] = f[j];
      }
      for(int j = 0 ; j < c[i] ; j++){
        tempd[j] = f[j + p[i] -1];
      }
      for(int j = 0 ; j < c[i] ; j++){
        f[j] = tempd[j];
      }
      for(int j = 0 ; j < p[i]-1 ; j++){
        f[j+c[i]] = tempu[j];
      }

      for(int j = 0 ; j < n ; j++){
        cout << f[j] << " ";
      } cout << endl;
    }

    cout << f[0] << endl;
  }
}

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

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
    for(int n, r; cin >> n >> r, n;){
        string yama;
        rep(i, n){
            char c = (n - i) + '0';
            yama.push_back(c);
        }
        
        while(r --){
            int p, c; cin >> p >> c;
            
            string str = yama.substr(p - 1, c);
            yama.replace(p - 1, c, "");
            yama = str + yama;
        }
        cout << yama[0] << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <deque>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
int n,r,catloc,catcnt;
int ans=0;
int main(int argc,char const* argv[])
{
  while(1)
    {
      ans=0;
      cin >> n >> r;
      if(!n) break;
      deque<int> card;
      for(int i=n-1;i>=0;i--)
	{
	  card.push_front(n-i);
	}
      for(int i=0;i<r;i++)
	{
	  cin >> catloc >> catcnt;
	  for(int j=catcnt;j>0;j--)
	    {
	      int tmp=card[catloc+catcnt-2];
	      card.erase(card.begin()+catloc+catcnt-2);
	      card.push_front(tmp);
	    }
	}
      cout << card[0] << endl;
    }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for (int i=(n)-1;i>=0;i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define REPS(i,f,n) for (int i=(f)-1;i>=(n);i--)
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
 
void slove(int n, int r){//n ?????° r?????????????????°?°
    stack<int> s;
    reps(i, 1, n + 1) s.push(i);//?????????
 
    rep(i, r){//r????????????
        int p, c;
        cin >> p >> c;
        stack<int> tmp1;
        stack<int> tmp2;

        rep(i, p - 1){
            tmp1.push(s.top());
            s.pop();
        }
        rep(i, c){
            tmp2.push(s.top());
            s.pop();
        }

        rep(i, p - 1){
            s.push(tmp1.top());
            tmp1.pop();
        }
        rep(i, c){
            s.push(tmp2.top());
            tmp2.pop();
        }
    }
 
    printf("%d\n", s.top());
    return;
}
 
int main(void){
    int n, r;
    cin >> n >> r;
    while(n != 0 || r != 0){
        slove(n, r);
        cin >> n >> r;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,r,p,c;
  int j;
  int card[50];
  while(1){
    cin>>n>>r;
    if(n==0 && r==0) break;
    j=1;
    for(int i=n-1;i>=0;i--){
      card[i]=j;
      j++;
    }
    for(int i=0;i<r;i++){
      cin>>p>>c;
      rotate(card,card+p-1,card+p+c-1);
   }
    cout<<card[0]<<endl;
  }
  return 0;
}