#include <bits/stdc++.h>
#include <atcoder/maxflow>
using namespace std;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) For(i, 0, n)
#define rFor(i, a, b) for(int i = (a); i >= (b); i--)
#define ALL(v) (v).begin(), (v).end()
#define rALL(v) (v).rbegin(), (v).rend()

using lint = long long;
using ld = long double;

int INF = 2000000000;
lint LINF = 1000000000000000000;

struct SetupIo {
    SetupIo() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cout << fixed << setprecision(15);
    }
} setupio;

int main() {
    int n;
    lint m;
    cin >> n >> m;
    vector<lint> x(n), y(n), goods;
    rep(i, n) {
        cin >> x[i] >> y[i];
        goods.emplace_back(x[i]);
        goods.emplace_back(y[i]);
    }
    sort(ALL(goods));
    goods.erase(unique(ALL(goods)), goods.end());
    int sz = goods.size();
    atcoder::mf_graph<int> g(1 + n + sz + 1);
    rep(i, n) {
        g.add_edge(0, i + 1, 1);
    }
    rep(i, n) {
        int id = lower_bound(ALL(goods), x[i]) - goods.begin();
        assert(goods[id] == x[i]);
        g.add_edge(i + 1, id + n + 1, 1);
        id = lower_bound(ALL(goods), y[i]) - goods.begin();
        assert(goods[id] == y[i]);
        g.add_edge(i + 1, id + n + 1, 1);
    }
    rep(i, sz) {
        g.add_edge(i + n + 1, n + sz + 1, 1);
    }
    cout << g.flow(0, n + sz + 1) << "\n";
}