#include <bits/stdc++.h>
using namespace std;
const int N = 5100;
int dp[N][N], x[N], n, m;
void read() {
  string junk;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> x[i] >> junk;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  read();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      dp[i][j] = dp[i - 1][j];
      if (j == x[i])
        for (int k = x[i]; k >= 1; k--)
          dp[i][j] = max(dp[i - 1][k] + 1, dp[i][j]);
    }
  for (int i = 1; i <= m; i++) dp[n][m + 1] = max(dp[n][m + 1], dp[n][i]);
  cout << n - dp[n][m + 1] << endl;
  return 0;
}
