#pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; using ld = long double; const vector dx = {0, 0, 1, -1}; const vector dy = {1, -1, 0, 0}; #define vec vector #define int long long #define double long double //cout< #define pq priority_queue #define all(V) begin(V),end(V) #define printpair(p) cout< template inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } #define mend(a,b) G[a].push_back(b) struct unionFind { vector par; vector siz; vector cnt; unionFind(int N): par(N+1), siz(N+1, 1), cnt(N+1, 0) { for (int i=0; i<=N; i++) par.at(i) = i; } int root(int x) { while (par.at(x) != x) { par.at(x) = par.at(par.at(x)); x = par.at(x); } return x; } bool merge(int x, int y) { x = root(x), y = root(y); if (x == y){ cnt.at(x)++; return false; } if (siz.at(x) < siz.at(y)) swap(x, y); siz.at(x) += siz.at(y); cnt.at(x) += cnt.at(y); par.at(y) = x; cnt.at(x)++; return true; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return siz.at(root(x)); } }; signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n,m;cin>>n>>m; vec C(n+1); vec Cv(n+1,vec()); rep(i,n){cin>>C[i+1];Cv[C[i+1]].push_back(i+1);} unionFind Z(n+1); vec rooot(n+1,-1); rep(i,m){ int a,b;cin>>a>>b; if(C[a]==C[b]){ Z.merge(a,b); rooot[C[a]]=Z.root(a); } } int ans=0; for(int i=1;i<=n;i++){ if(Cv[i].size()<=1){continue;} for(int v:Cv[i]){ if(rooot[i]==-1){ rooot[i]=v;continue; } if(Z.root(v)!=rooot[i]){ Z.merge(rooot[i],v); ans++; } } } cout<