#include #include #define chmin(x,y) (x) = min((x),(y)) #define chmax(x,y) (x) = max((x),(y)) #define ld long double using namespace std; using namespace atcoder; using ll = long long; const ll mod = 998244353; using mint = modint998244353; using Graph = vector>; const vector dx = {1,0,-1,0}, dy = {0,1,0,-1}; int main(){ int N,M; cin >> N >> M; vector C(N); for(int i = 0; i < N; i++) cin >> C[i]; dsu uf(N); while(M--){ int u,v; cin >> u >> v; --u; --v; if(C[u] == C[v]) uf.merge(u,v); } map mp; for(int i = 0; i < N; i++){ if(uf.leader(i) == i) mp[C[i]]++; } int ans = 0; for(auto p : mp) ans += p.second - 1; cout << ans << endl; }