#include <bits/stdc++.h>
using namespace std;
int n, m, s[5010], d[5010], res;
int main() {
  cin >> n >> m;
  for (int i = (int)1; i <= (int)n; ++i) {
    char foo[30];
    cin >> s[i] >> foo;
  }
  for (int i = (int)0; i <= (int)n + 1 - 1; ++i) d[i] = -1;
  d[1] = 0;
  for (int i = (int)1; i <= (int)n; ++i)
    for (int j = (int)1; j <= (int)m; ++j)
      d[j + 1] = max(d[j + 1], d[j]), d[j] += (s[i] == j);
  for (int j = (int)1; j <= (int)m; ++j) res = max(res, d[j]);
  cout << n - res;
}
