let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let uf = Array.make (n+1) (-1) in
  let rec find x =
    if uf.(x) < 0 then x else begin
      let x' = find uf.(x) in
      uf.(x) <- x'; x'
    end in
  let unite x y =
    let x, y = find x, find y in
    if x <> y then begin
      if uf.(x) < uf.(y) then (
        uf.(x) <- uf.(x) + uf.(y); uf.(y) <- x
      ) else (
        uf.(y) <- uf.(x) + uf.(y); uf.(x) <- y)
    end in
  let same x y = find x = find y in

  let p = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  for _ = 1 to m do Scanf.scanf " %d %d" unite done;

  Array.init n (fun i -> if same (i+1) p.(i) then 1 else 0)
  |> Array.fold_left (+) 0 |> Printf.printf "%d\n"