class UnionFind: def __init__(self, n): self.n = n self.parent_size = [-1] * n def leader(self, a): if self.parent_size[a] < 0: return a self.parent_size[a] = self.leader(self.parent_size[a]) return self.parent_size[a] def merge(self, a, b): x, y = self.leader(a), self.leader(b) if x == y: return if abs(self.parent_size[x]) < abs(self.parent_size[y]): x, y = y, x self.parent_size[x] += self.parent_size[y] self.parent_size[y] = x return def same(self, a, b): return self.leader(a) == self.leader(b) def size(self, a): return abs(self.parent_size[self.leader(a)]) def groups(self): result=[[] for _ in range(self.n)] for i in range(self.n): result[self.leader(i)].append(i) return [r for r in result if r != []] N,M=map(int,input().split()) C=list(map(int,input().split())) G=[[] for _ in range(N)] for _ in range(M): u,v=map(int,input().split()) u-=1;v-=1 G[u].append(v) G[v].append(u) uf=UnionFind(N) vis=[0 for _ in range(N)] from collections import deque,defaultdict Q=deque() Q.append(0) while Q: cur=Q.popleft() vis[cur]=1 for nxt in G[cur]: if C[cur]==C[nxt]:uf.merge(cur,nxt) if vis[nxt]==0:Q.append(nxt) D=defaultdict(set) for i in range(N): L=uf.leader(i) D[C[L]].add(L) ans=0 for k,v in D.items(): ans+=len(v)-1 print(ans)