from collections import deque import sys input = sys.stdin.readline N, M = map(int, input().split()) C = list(map(int, input().split())) graph = [[] for _ in range(N)] for i in range(M): u, v = map(int, input().split()) u -= 1 v -= 1 if C[u] == C[v]: graph[u].append(v) graph[v].append(u) ans = 0 Clen = [0 for _ in range(N + 1)] for i in range(N): Clen[C[i]] += 1 isvisited = [False for _ in range(N)] dq = deque() for i in range(N): if isvisited[i]: continue isvisited[i] = True dq.append(i) while len(dq): Clen[C[i]] -= 1 p = dq.popleft() for x in graph[p]: if isvisited[x]: continue isvisited[x] = True dq.append(x) Clen[C[i]] += 1 # print(Clen) for i in range(1, N + 1): ans += max(0, Clen[i] - 1) print(ans)