import sys sys.setrecursionlimit(10 ** 6) def dfs(now, g, visited): visited[now] = True for nex in g[now]: if visited[nex]: continue dfs(nex, g, visited) n, m = map(int, input().split()) g = [[] for _ in range(n)] c = list(map(int, input().split())) for _ in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 if c[u] == c[v]: g[u].append(v) g[v].append(u) com = [0] * n visited = [False] * n for i in range(n): if not visited[i]: dfs(i, g, visited) com[c[i] - 1] += 1 ans = 0 for i in range(n): if com[i] != 0: ans += com[i] - 1 print(ans)