#include <bits/stdc++.h>
using namespace std;
int a[5010];
int dp[5010][5010];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    double x;
    cin >> a[i] >> x;
  }
  memset(dp, 1, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) dp[i][0] = dp[i - 1][0] + (a[i - 1] != 1);
  for (int j = 1; j < m; j++) {
    for (int i = 1; i <= n; i++) {
      dp[i][j] = min(dp[i][j],
                     min(dp[i - 1][j], dp[i - 1][j - 1]) + (a[i - 1] != j + 1));
      dp[i][j] = min(dp[i][j], dp[i][j - 1] - (a[i - 1] == j + 1));
    }
  }
  int res = dp[n][0];
  for (int i = 1; i < m; i++) res = min(res, dp[n][i]);
  cout << res << endl;
  return 0;
}
