class UnionFind: def __init__(self, size): self.parent = [i for i in range(size)] def find(self, x): if self.parent[x] != x: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def merge(self, x, y): x_root = self.find(x) y_root = self.find(y) if x_root != y_root: self.parent[x_root] = y_root def leader(self, x): return self.find(x) # Read N and M N, M = map(int, input().split()) # Read C C = list(map(int, input().split())) # Initialize UnionFind uf = UnionFind(N) # Process the edges for _ in range(M): u, v = map(int, input().split()) u -= 1 v -= 1 if C[u] == C[v]: uf.merge(u, v) # Count the groups mp = {} for i in range(N): leader = uf.leader(i) if leader == i: mp[C[i]] = mp.get(C[i], 0) + 1 # Calculate the answer ans = sum(value - 1 for value in mp.values()) print(ans)