#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void smn(T &a, const T &b) {
  if (b < a) a = b;
}
template <class T>
inline void smx(T &a, const T &b) {
  if (b > a) a = b;
}
template <class T>
inline T _rev(const T &a) {
  T _ = a;
  reverse(_.begin(), _.end());
  return _;
}
const double eps = 1e-8;
const long double leps = 1e-14;
const int MN = 5000 + 100, INF = (1u << 31) - 1;
;
int d[MN][MN];
int n, m;
double all[MN];
int p[MN];
pair<int, double> srt[MN];
int fnd(int a, int b) {
  if (a >= n) return 0;
  int &res = d[a][b];
  if (res != -1) return res;
  res = INF;
  if (srt[a].second >= all[b]) smn(res, fnd(a + 1, p[a]));
  smn(res, 1 + fnd(a + 1, b));
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> srt[i].first >> srt[i].second;
    all[i] = srt[i].second;
  }
  sort(srt, srt + n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (abs(srt[i].second - all[j]) < eps) p[i] = j;
  memset(d, -1, sizeof(d));
  cout << fnd(0, 0) << '\n';
  return 0;
}
