#include <bits/stdc++.h>
using namespace std;
int S[5003][5003], M[5003][5003], A[5003], W[5003], n, i, j;
double x;
int f(int i, int mx) {
  if (i == n + 1) return 0;
  int &r = M[i][mx];
  if (r != -1) return r;
  if (A[mx] < A[i])
    r = min(f(i + 1, mx) + 1, f(i + 1, i) + S[i][A[i] - 1] - S[i][A[mx] - 1]);
  else
    r = f(i + 1, mx);
  return r;
}
int main() {
  cin >> n >> i;
  for (i = 1; i <= n; i++) cin >> A[i] >> x;
  for (i = n; i; i--) {
    W[A[i]]++;
    for (j = 1; j < A[i]; j++) S[i][j] = S[i][j - 1] + W[j];
  }
  memset(M, -1, sizeof M);
  cout << f(1, 0);
  return 0;
}
