#include <bits/stdc++.h>
using namespace std;
struct Item {
  int t;
  double x;
  bool operator<(const Item &sec) const { return x < sec.x; }
} arr[5005];
int q[5005];
int dp[5005][5005];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d%lf", &arr[i].t, &arr[i].x);
    --arr[i].t;
    q[arr[i].t]++;
  }
  sort(arr, arr + n);
  memset(dp, 0x7f, sizeof dp);
  dp[0][0] = 0;
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= m; ++j) {
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (arr[i].t != j));
      dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
