############################################################# import sys sys.setrecursionlimit(10**7) from heapq import heappop,heappush from collections import deque,defaultdict,Counter from bisect import bisect_left, bisect_right from itertools import product,combinations,permutations from math import sin,cos #from math import isqrt #DO NOT USE PyPy ipt = sys.stdin.readline iin = lambda :int(ipt()) lmin = lambda :list(map(int,ipt().split())) ############################################################# N,M = lmin() C = lmin() G = [[] for _ in range(N)] for _ in range(M): u,v = lmin() u,v = u-1,v-1 if C[u] == C[v]: G[u].append(v) G[v].append(u) cnt = [0]*(N+1) visited = [0]*N for i in range(N): if visited[i]: continue cnt[C[i]] += 1 visited[i] = 1 st = [i] while st: cur = st.pop() for nxt in G[cur]: if visited[nxt]: continue visited[nxt] = 1 st.append(nxt) ans = 0 for i in range(N): ans += max(0, cnt[i]-1) print(ans)