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 <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
	int n, r;
	int card[55];
	int a[55], b[55];
	while(cin >> n >> r, n+r){
		rep(i, n) card[i] = n-i;
		int p, c;
		for(int i=0; i< r; i++){
			rep(i, 55){ a[i] = 0; b[i] = 0;}
			cin >> p >> c;

			rep(i, p-1) a[i] = card[i];
			rep(i, c) b[i] = card[p+i-1];
			rep(i, c) card[i] = b[i];
			rep(i, p-1) card[i+c] = a[i];

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

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

int main(){
  int card1[50],card2[50];
  int n,r;
  int p,c;

  while(1){
    cin>>n>>r;
    if(n+r==0)break;
    for(int i=0;i<n;i++)  card1[i]=n-i;
    for(int i=0;i<r;i++){
      cin>>p>>c;
      for(int i=0;i<c;i++) card2[i]=card1[p-1+i];
      for(int i=c;i<p;i++) card2[i]=card1[i-c];
      if(p>=c){
	for(int i=p;i<n;i++){
	  if(p+c-1==n) card2[i]=card1[i-c];
	  else card2[i]=card1[i-1+c];
	}
      }
      for(int i=0;i<n;i++)card1[i]=card2[i];
    }
    cout<<card2[0]<<endl;
  }

  return 0;
}

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

using namespace std;

int main(int argc, char const* argv[])
{
	int n, r, p, c;

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

		std::vector<int> cards(n);

		for(int i = 0; i < n; ++i) {
			cards.at(n - i - 1) = i + 1;
		}

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

			std::vector<int> temp_p;
			std::vector<int> temp_c;

			std::copy_n(cards.begin(), p - 1, std::back_inserter(temp_p));
			std::copy_n(cards.begin() + p - 1, c, std::back_inserter(temp_c));

			std::copy(temp_c.begin(), temp_c.end(), cards.begin());
			std::copy(temp_p.begin(), temp_p.end(), cards.begin() + c);
		}

		std::cout << cards.at(0) << std::endl;
	}

	return 0;
}

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

int main() {
  int N, R, P, C;
  while (cin >> N && cin >> R && N > 0 && R > 0) {
    int n[N];
    for (int i = 0; i < N; i++) n[i] = N-i;

    while (R > 0) {
      cin >> P; 
      cin >> C;
      rotate(n, n+P-1, n+P+C-1);
      R--;
    }
        cout << n[0] << endl;
  }
  
}

C++: #include <bits/stdc++.h>

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e09

using namespace std;

int main(){
  int n, r;
  while(cin >> n and cin >> r and n+r){
    vector<int> card(n);
    iota(ALL(card), 1);
    reverse(ALL(card));
    REP(i, r){
      int p, c;
      cin >> p >> c;
      p--;
      int tmp[c];
      REP(j, c) tmp[j] = card[p+j];
      for(int j=p-1; j>=0; j--) card[j+c] = card[j];
      REP(j, c) card[j] = tmp[j];
    }
    cout << card[0] << endl;
  }
  return 0;
}

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

int main(){
  int n=1,r=1,p,c;
  vector<int> deck,temp,ans;

  while(1){
    cin >> n >> r;
    if(n==0&&r==0)break;
    for(int i=n; i>0; --i)deck.push_back(i); //???????????????
    for(int i=0; i<r; ++i){
      cin >> p >> c;
      copy(deck.begin()+p-1,deck.begin()+p+c-1,back_inserter(temp));
      deck.erase(deck.begin()+p-1,deck.begin()+p+c-1);
      copy(deck.begin(),deck.end(),back_inserter(temp));
      deck=temp;
      temp.clear();
    }
    ans.push_back(deck[0]);
    deck.clear();
  }
  for(auto x: ans)cout << x << endl;
  return 0;
}

C++: #define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main() {
  int n,r;
  while(cin>>n>>r){
    if(n==0 && r==0) return 0;
    
    vector<pair<int,int>> A(n);
    rep(i,n) A[i]={i,n-i};
    
    int p,c;
    rep(i,r){
      cin>>p>>c;
      for(int j=p-1;j<p+c-1;j++){
        A[j].first=j-p+1;
      }
      for(int j=0;j<p-1;j++){
        A[j].first=c+j;
      }
      sort(ALL(A));
    }
    cout<<A[0].second<<endl;
  }
  
  return 0;
}

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

int main(){
  int n, r, a[100], b[100];
  while(cin >> n >> r && n && r){
    for(int i = 0;i < n;i ++){
      a[i] = n-i;
    }
    for(int i = 0;i < r;i ++){
      int c, p;
      cin >> p >> c;
      for(int j = p-1;j<p+c-1;j++){
        b[j] = a[j];
      }
      for(int j = p-2;j>=0;j--){
        a[j+c] = a[j];
      }
      for(int j = p-1;j<p+c-1;j++){
        a[j-(p-1)] = b[j];
      }
    }
    cout << a[0] << endl;
  }
  return 0;
}

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

int main(){
  int card[50],tmp[50];
  int n,r,p,c;

  while(cin >> n >> r,n){
    for(int i=0;i<n;i++)card[i] = n-i;

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

      for(int i=0;i<c;i++)tmp[i] = card[p-1+i];
      for(int i=p-1;i>=0;i--)card[i+c] = card[i];
      for(int i=0;i<c;i++)card[i] = tmp[i];
    }
    cout << card[0] << endl;
  }
}

C++: //#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <cstring>
#include <climits>
#define INF INT_MAX / 2
using namespace std;

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

vector<int> cut(vector<int> vi,int p,int c){
	vector<int> ret;
	for(int i=p-1;i<p-1+c;i++)
		ret.push_back(vi[i]);
	for(int i=0;i<p-1;i++)
		ret.push_back(vi[i]);
	for(int i=p+c-1;i<vi.size();i++)
		ret.push_back(vi[i]);
	return ret;
}

int main(void) {
	int n;int r;

	while(cin >> n >> r,n+r!=0){
	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;
		a = cut(a,p,c);
	}
	cout << a[0] << endl;
}
}

// command ctrl 上下
// command D
// command caps G → '' ""

C++: #include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std; 
int main(){
  int n,r;
  int a[60]={}; 
  while(cin>>n>>r){
    if(n==0&&r==0)break;
    for(int i=0;i<n;i++){
      a[i]=n-i;
    }
    int b[60]={};
    for(int i=0;i<r;i++){
      int p,c;
      cin>>p>>c;
      for(int j=0;j<c;j++){
	b[j]=a[p-1+j];	
      }
      for(int j=0;j<p-1;j++){
	b[j+c]=a[j];
      }
      for(int j=0;j<n-p-c;j++){
	b[j+p]=a[j+p];
      }

      for(int i=0;i<n;i++){	
	a[i]=b[i];
      }
    }
   
    cout<<b[0]<<endl;
  }  

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

void solve(){
}

int main(){
  int n,r;

  while(cin>>n>>r,n||r){
    vector<int> v;
    REP(i,1,n+1) v.push_back(i);
    rep(i,r){
      int p,c;
      cin>>p>>c;

      rep(j,c){
        int tmp = v[n-p-c+1];
        v.erase(v.begin() + (n-p-c+1));
        v.push_back(tmp);
      }
    }

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