package main import . "fmt" import . "os" import bf "bufio" func main() { rd:=bf.NewReader(Stdin) var n,m int Fscan(rd,&n,&m) cs:=make([]int,n) for i:=range cs { Fscan(rd,&cs[i]) } t:=make([][]int,n) for ;m>0;m-- { var u,v int Fscan(rd,&u,&v) u-- v-- t[u]=append(t[u],v) t[v]=append(t[v],u) } visited:=make([]bool,n) g:=make(map[int]int) for i,c:=range cs { if visited[i] { continue } g[c]++ visited[i]=true p:=t[i][:] for len(p)>0 { e:=p[len(p)-1] p=p[:len(p)-1] if cs[e]!=c||visited[e] { continue } visited[e]=true p=append(p,t[e]...) } } var ans int for _,c:=range g { if c>0 { ans+=c-1 } } Println(ans) }