N,M=map(int,input().split()) C=list(map(int,input().split())) # UnionFind Group = [i for i in range(N)] # グループ分け Nodes = [1]*(N) # 各グループのノードの数 def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): if Nodes[find(x)] < Nodes[find(y)]: Nodes[find(y)] += Nodes[find(x)] Nodes[find(x)] = 0 Group[find(x)] = find(y) else: Nodes[find(x)] += Nodes[find(y)] Nodes[find(y)] = 0 Group[find(y)] = find(x) for i in range(M): x,y=map(int,input().split()) if C[x-1]==C[y-1]: Union(x-1,y-1) LIST=[[] for i in range(10**6)] for i in range(N): if find(i)==i: LIST[C[i]].append(i) ANS=0 for i in range(10**6): ANS+=max(0,len(LIST[i])-1) print(ANS)