N, M = map(int, input().split()) C = list(map(int, input().split())) UV = [map(int, input().split()) for _ in range(M)] graph = [[] for _ in range(N)] for U, V in UV: U -= 1 V -= 1 if C[U] == C[V]: graph[U].append(V) graph[V].append(U) ac = [False] * N col = [False] * N ans = 0 for i in range(N): if ac[i]: continue if col[C[i]-1]: ans += 1 col[C[i]-1] = True q = [i] while q: now = q.pop() if ac[now]: continue ac[now] = True for g in graph[now]: if ac[g]: continue q.append(g) print(ans)