from collections import defaultdict,deque N,M=map(int,input().split()) C=list(map(int,input().split())) G=defaultdict(list) for i in range(M): u,v=map(int,input().split()) if(C[u-1]==C[v-1]): G[u].append(v) G[v].append(u) #連結成分の個数-色の種類数 T=1 c=0 seen=[False]*(N+1) while T<=N: que=deque([T]) seen[T]=True while len(que): p=que.popleft() for q in G[p]: if(not seen[q]): seen[q]=True que.append(q) while T<=N and seen[T]: T+=1 c+=1 print(c-len(set(C)))