from collections import deque N, M = map(int, input().split()) C = list(map(int, input().split())) #色iの連結成分の個数はcnt[i]個 cnt = [0 for _ in range(N + 1)] G = [[] for _ in range(N + 1)] for _ in range(M): a, b = map(int, input().split()) G[a].append(b) G[b].append(a) vis = set() for s_id in range(1, N + 1): if s_id in vis: continue vis.add(s_id) FIFO = deque() FIFO.append(s_id) color = C[s_id - 1] cnt[color] += 1 while FIFO: now_vid = FIFO.popleft() for ne_vid in G[now_vid]: if ne_vid not in vis and C[now_vid - 1] == C[ne_vid - 1]: vis.add(ne_vid) FIFO.append(ne_vid) ans = 0 for i in range(len(cnt)): if cnt[i] >= 2: ans += cnt[i] - 1 print(ans)