#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; typedef pair P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const static_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second; return os;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} int main(){ int n, m; cin >> n >> m; vi c(n); cin >> c; dsu uf(n); rep(i, m){ int u, v; cin >> u >> v; u--; v--; if(c[u] == c[v]) uf.merge(u, v); } vi b(n); auto f = uf.groups(); for(auto& v : f){ int ci = c[v[0]]; b[ci]++; } int ans = 0; rep(i, n){ ans += max(b[i] - 1, 0); } cout << ans << "\n"; return 0; }