def INT(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) class UnionFind: def __init__(self, N): self.root = [_ for _ in range(N)] self.rank = [0] * N self.size = [1] * N def find(self, x): if self.root[x] == x: return x else: # 根を予め取得し,経路圧縮する self.root[x] = self.find(self.root[x]) return self.root[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return else: if self.rank[x] > self.rank[y]: self.size[x] += self.size[y] self.root[y] = x else: self.size[y] += self.size[x] self.root[x] = y if self.rank[x] == self.rank[y]: self.rank[y] += 1 def same(self, x, y): return self.find(x) == self.find(y) def getSizeOfSet(self, x): return self.size[self.find(x)] N, M = MI() C = LI() dsu = UnionFind(N) for _ in range(M): u, v = MI() u -= 1 v -= 1 if C[u] == C[v]: dsu.union(u, v) cl = [[] for _ in range(N)] for i in range(N): cl[C[i] - 1].append(i) ans = 0 for i in range(N): if len(cl[i]) < 1: continue root_c = set() all_one = True for c in cl[i]: root_c.add(dsu.root[c]) if dsu.getSizeOfSet(c) != 1: all_one = False if all_one: ans += len(cl[i]) - 1 else: ans += len(root_c) - 1 print(ans)