#include <bits/stdc++.h>
using namespace std;
int a[5010], ps[5010], dp[5010][5010];
int main() {
  int n, m;
  double x;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> x;
  }
  for (int i = a[n - 1]; i < n; i++) ps[i]++;
  for (int i = n - 2; i >= 0; i--) {
    for (int j = 1; j <= m; j++) {
      if (a[i] <= j || ps[a[i] - 1] - ps[j - 1] <= 0)
        dp[i][j] = dp[i + 1][j];
      else {
        dp[i][j] =
            min(dp[i + 1][j] + 1, dp[i + 1][a[i]] + ps[a[i] - 1] - ps[j - 1]);
      }
    }
    for (int j = a[i]; j < n; j++) ps[j]++;
  }
  cout << dp[0][1];
}
