#include <bits/stdc++.h> int main() { int N, M; std::cin >> N >> M; std::vector<int> C(N+1); std::vector<std::vector<int>> G(N+1); for (int i = 1; i <= N; ++i) std::cin >> C[i]; while (M--) { int u, v; std::cin >> u >> v; if (C[u] == C[v]) { G[u].push_back(v); G[v].push_back(u); } } std::vector<int> groups(N+1); std::vector<bool> done(N+1, false); for (int s = 1; s <= N; ++s) if (!done[s]) { std::vector<int> bfs; bfs.reserve(N); bfs.push_back(s); done[s] = true; for (auto u = bfs.begin(); u != bfs.end(); ++u) for (const int &v : G[*u]) if (!done[v]) bfs.push_back(v), done[v] = true; ++groups[C[s]]; } int answer{}; for (int c = 1; c <= N; ++c) if (groups[c] > 1) answer += groups[c] - 1; std::cout << answer << '\n'; }