#include #define rep(i,n) for(int i=0;i<(n);++i) using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n,m; cin >> n >> m; vector c(n); rep(i,n) cin >> c[i],c[i]--; vector> g(n); rep(i,m){ int a,b; cin >> a >> b; a--;b--; if(c[a]!=c[b]) continue; g[a].push_back(b); g[b].push_back(a); } vector cnt(m,0); vector dist(n,false); rep(i,n){ if(dist[i]) continue; queue q; q.push(i); dist[i]=true; while(!q.empty()){ int t = q.front(); q.pop(); for(int x:g[t]){ if(dist[x]) continue; dist[x]=true; q.push(x); } } cnt[c[i]]++; } int ans = 0; rep(i,m) if(cnt[i]>0) ans += cnt[i]-1; cout << ans << endl; }