#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e3;
int n, m, dp[N + 1][N + 1];
pair<double, int> a[N];
void update(int& v, int val) {
  if (v == -1 || val < v) v = val;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i].second >> a[i].first;
  sort(a, a + n);
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (dp[i][j] != -1) {
        update(dp[i][j + 1], dp[i][j]);
        if (a[i].second == j + 1)
          update(dp[i + 1][j], dp[i][j]);
        else
          update(dp[i + 1][j], dp[i][j] + 1);
      }
  int ans = -1;
  for (int i = 0; i <= m; i++)
    if (dp[n][i] != -1) update(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}
