#include template void print(const T &t) { std::cout << t << '\n'; } template void print(const Head &head, const Tail &... tail) { std::cout << head << ' '; print(tail...); } template using v = std::vector; using ll = long long; using std::cin; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); int n, m; cin >> n >> m; v> s(n); v col(n); for (int i = 0; i < n; ++i) { int b, c; cin >> b >> c; c--; s[c][b]++; col[c] += 1; } int ans = 0; for (int i = 0; i < n; ++i) { if (!col[i]) { continue; } int max = 0; for (auto &[key, value]: s[i]) { max = std::max(max, value); } ans += col[i] - max; } print(ans); }