#include using namespace std; using ll = long long; using P = pair; using T = tuple; // #include // using namespace atcoder; // using mint = modint1000000007; #define rep(i, n) for(ll i = 0; i < n; i++) int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); ll n, m; cin >> n >> m; vector c(n); rep(i,n) cin >> c[i]; vector> Graph(n); rep(i,m) { ll u, v; cin >> u >> v; u--; v--; Graph[u].emplace_back(v); Graph[v].emplace_back(u); } vector cnt(n+1,0); vector vis(n,false); queue todo; rep(i,n) { if( vis[i] ) continue; todo.push(i); while( !todo.empty() ) { ll now = todo.front(); todo.pop(); if( vis[now] ) continue; vis[now] = true; for(auto to:Graph[now]) { if( vis[to] || c[now] != c[to] ) continue; todo.push(to); } } cnt[c[i]]++; } ll ans = 0; rep(i,n+1) ans += max(cnt[i]-1,0ll); cout << ans << endl; return 0; }