from collections import defaultdict as dd class UnionFind: def __init__(self, n): self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x N, M = map(int, input().split()) c = list(map(int, input().split())) gc = dd(lambda: -1) for ci in c: gc[ci] += 1 uf = UnionFind(N) for _ in range(M): u, v = map(lambda x: int(x) - 1, input().split()) if c[u] == c[v] and uf.find(u) != uf.find(v): uf.union(u, v) gc[c[u]] -= 1 # print(sum(gc.values()) - len(gc.keys())) print(sum(gc.values()))