#include <bits/stdc++.h>
using namespace std;
long long int ESP = 1e18;
long long int FCB = 1e9 + 7;
long long int prime = 119;
long long int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int n, m;
  cin >> n >> m;
  vector<double> adj[m + 1];
  vector<double> vv;
  for (long long int i = 0; i < n; i++) {
    long long int type;
    cin >> type;
    double x;
    cin >> x;
    adj[type].push_back(x);
  }
  for (long long int j = 1; j < m + 1; j++) sort(adj[j].begin(), adj[j].end());
  for (long long int j = 1; j < m + 1; j++) {
    for (long long int i = 0; i < adj[j].size(); i++) {
      vv.push_back(adj[j][i]);
    }
  }
  long long int dp[n];
  for (long long int i = 0; i < n; i++) dp[i] = 1;
  for (long long int j = 1; j < n; j++) {
    for (long long int i = 0; i < j; i++) {
      if (vv[j] > vv[i]) dp[j] = max(dp[j], 1 + dp[i]);
    }
  }
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) ans = max(ans, dp[i]);
  cout << n - ans << "\n";
  return 0;
}
