#include <bits/stdc++.h>
using namespace std;
const int MN = 5010;
const int inf = 10000000;
int n, m, cnt[MN], a[MN];
double x;
void Init() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d%lf", &a[i], &x);
    cnt[a[i]]++;
  }
  for (int i = 1; i <= m; i++) {
    cnt[i] += cnt[i - 1];
  }
  for (int i = n - 1; i >= 0; i--) {
    a[i] = --cnt[a[i]];
  }
  vector<int> d(n + 1, inf);
  d[0] = -inf;
  for (int i = 0; i < n; i++) {
    int j = lower_bound(d.begin(), d.end(), a[i]) - d.begin();
    d[j] = a[i];
  }
  for (int i = n; i >= 0; i--) {
    if (d[i] != inf) {
      printf("%d\n", n - i);
      exit(0);
    }
  }
}
void solve() {}
int main() {
  Init();
  return 0;
}
