def find(x): if P[x] == x: return x else: P[x] = find(P[x]) #経路圧縮 return P[x] # return find(P[x]) #経路圧縮なし def same(x,y): return find(x) == find(y) def merge(x,y): x = find(x) y = find(y) if x == y: return 0 if x > y: x,y = y,x P[y] = x N,M = map(int,input().split()) P = [i for i in range(N)] C = list(map(int,input().split())) G = [[] for _ in range(N)] for i,c in enumerate(C): c -= 1 G[c].append(i) for i in range(M): u,v = map(int,input().split()) u -= 1 v -= 1 if C[u] == C[v]: merge(u,v) ans = 0 for i in range(N): if G[i]: if len(G[i]) == 1: continue ng = len(G[i]) for j in range(1,ng): if not same(G[i][0],G[i][j]): merge(G[i][0],G[i][j]) ans += 1 print(ans)