#include using namespace std; #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define repo(i, n) for (ll i = 1; i <= (ll)(n); ++i) typedef long long ll; ll n, m; ll ans; void dfs(const vector> &G, int v, vector &seen, vector &c) { seen[v] = true; for (auto next_v : G[v]) { if (seen[next_v] || c[v] != c[next_v]) continue; dfs(G, next_v,seen,c); } } int main() { cin >> n >> m; vector c(n); for (ll i = 0; i < n; ++i) cin >> c[i]; vector> G(n); vector seen(n,false); for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; --a, --b; G[a].push_back(b); G[b].push_back(a); } vector count(n,0); vector checkd(n,false); for (ll i = 0; i < n; ++i) { if (seen[i]) continue; else { if(!checkd[c[i]-1]) {checkd[c[i]-1] = true; dfs(G,i,seen,c);} else {++count[c[i]-1];dfs(G,i,seen,c);} } } ll ans = 0; ans = accumulate(count.begin(), count.end(), 0); cout << ans << endl; }