#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair Pii; const ll mod = 998244353; struct unionfind { vector group; vector rank; unionfind() { unionfind(0); } unionfind(int n) { group = vector(n); rank = vector(n); for (int i = 0; i < n; i++) group[i] = i; } int root(int x) { if (group[x] == x) return x; return group[x] = root(group[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rank[rx] > rank[ry]) group[ry] = rx; else if (rank[ry] > rank[rx]) group[rx] = ry; else if (rx != ry) { group[ry] = rx; rank[rx]++; } } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector c(n); for (auto &x: c) cin >> x; vector uv(m); for (auto &[u, v]: uv) { cin >> u >> v; u--; v--; } unionfind uf(n); for (auto &[u, v]: uv) { if (c[u] == c[v]) { uf.unite(u, v); } } unordered_map> group; for (int i = 0; i < n; i++) { group[c[i]].insert(uf.root(i)); } int ans = 0; for (auto &[k, v]: group) { ans += max(0, (int) v.size() - 1); } cout << ans << endl; return 0; }