#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); ++i) #include int main() { int n,m;cin>>n>>m; vector c(n); rep(i,n)cin>>c[i]; map> leads; rep(i, n) leads[c[i]].insert(i); atcoder::dsu d(n); rep(_, m) { int a, b; cin >> a >> b; --a, --b; if (c[a] == c[b]) { int la = d.leader(a); int lb = d.leader(b); if (la != lb) { d.merge(a, b); int nl = d.leader(a); leads[c[a]].erase(la); leads[c[b]].erase(lb); leads[c[nl]].insert(nl); } } } int ans = 0; for (auto [_, s] : leads) { ans += s.size() - 1; } cout << ans << endl; return 0; }