#include using namespace std; template bool cmin(A& a, B b) { return a > b && (a = b, true); } template bool cmax(A& a, B b) { return a < b && (a = b, true); } signed main() { cin.tie(nullptr)->sync_with_stdio(false); long N, M; cin >> N >> M; vector> V(N); for (long i = 0; i < N; i++) { long a, b; cin >> a >> b, a--, b--; V.at(i) = {a, b}; } vector> V2(M); for (const auto& [a, b] : V) V2.at(a).insert(b); long ans = 0; set SE; for (const auto& se : V2) { bool b = 0; for (const auto& a : se) { if (SE.count(a)) { b = 1; } else { SE.insert(a); } } if (b) ans++; } cout << ans << '\n'; }