(* persistent array *)
module PArray : sig
  type 'a t

  val init : int -> (int -> 'a) -> 'a t
  val make : int -> 'a -> 'a t
  val of_list : 'a list -> 'a t
  val get : 'a t -> int -> 'a
  val set : 'a t -> int -> 'a -> 'a t
  (** [set a n x] returns a persistent array replacing element number [n] of [a] with [x].
     [a] is *not* modified. *)
  val length : 'a t -> int
  val to_list : 'a t -> 'a list
  val iter : ('a -> unit) -> 'a t -> unit
  val iteri : (int -> 'a -> unit) -> 'a t -> unit
  val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
  val fold_right : ('b -> 'a -> 'a) -> 'b t -> 'a -> 'a
end = struct
  type 'a t = 'a data ref
  and 'a data = Arr of 'a array | Diff of int * 'a * 'a t

  let init n f = ref (Arr (Array.init n f))
  let make n v = ref (Arr (Array.make n v))
  let of_list l = ref (Arr (Array.of_list l))

  let rec reroot k = function
    | { contents = Arr a } -> k a
    | { contents = Diff (i, v, t') } as t ->
        reroot (fun a ->
          t' := Diff (i, a.(i), t);
          a.(i) <- v;
          k a) t'
  let reroot k = function
    | { contents = Arr a } -> k a
    | { contents = Diff (_, _, _) } as t ->
        reroot (fun a -> t := Arr a; k a) t

  let rec get t i = reroot (fun a -> a.(i)) t

  let set t i v =
    reroot (fun a ->
      if v = a.(i) then t
      else begin
        let result = ref (Arr a) in
        t := Diff (i, a.(i), result);
        a.(i) <- v;
        result
      end) t

  let length t = reroot Array.length t
  let to_list t = reroot Array.to_list t
  let iter f = reroot (Array.iter f)
  let iteri f = reroot (Array.iteri f)
  let fold_left f x = reroot (Array.fold_left f x)
  let fold_right f t x = reroot (fun a -> Array.fold_right f a x) t
end

(* persistent union-find data structure *)
module PUnionFind : sig
  type t
  type class_

  val make : int -> t
  val find : t -> int -> class_
  val union : t -> int -> int -> t
end = struct
  type t = { rank : int PArray.t; mutable parent : int PArray.t }
  type class_ = int

  let make n = { rank = PArray.make n 0; parent = PArray.init n (fun i -> i) }

  let rec find parent i k =
    let j = PArray.get parent i in
    if i = j then k parent i
    else find parent j (fun parent r -> k (PArray.set parent i r) r)
  let find ({ parent } as h) i = find parent i (fun parent r ->
    h.parent <- parent;
    r)

  let union uf x y =
    let cx = find uf x in
    let cy = find uf y in
    if cx = cy then uf
    else begin
      let rx = PArray.get uf.rank x in
      let ry = PArray.get uf.rank y in
      match compare rx ry with
      | -1 -> { uf with parent = PArray.set uf.parent cx cy }
      | 1 -> { uf with parent = PArray.set uf.parent cy cx }
      | 0 -> { rank = PArray.set uf.rank cx (cx + 1); parent = PArray.set uf.parent cy cx }
    end
end

module MultiSet = struct
  module type S = sig
    type elt
    type t
    val empty : t
    val is_empty : t -> bool
    val mem : elt -> t -> bool
    val count : elt -> t -> int
    val add : elt -> t -> t
    val remove : elt -> t -> t
    val clear : elt -> t -> t
    val cardinal : t -> int
    val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
    val min_elt : t -> elt
    val subset : t -> t -> bool
    val inter : t -> t -> t
  end

  module Make (E : Set.OrderedType) : S with type elt = E.t = struct
    module EltMap = Map.Make (E)
    type elt = EltMap.key
    type t = int EltMap.t

    let empty = EltMap.empty
    let is_empty = EltMap.is_empty
    let mem = EltMap.mem
    let count x m = try EltMap.find x m with Not_found -> 0
    let add x m = EltMap.add x (count x m + 1) m
    let remove x m =
      match EltMap.find x m with
      | 1 -> EltMap.remove x m
      | n -> EltMap.add x (n - 1) m
      | exception Not_found -> m
    let clear = EltMap.remove
    let cardinal m = EltMap.fold (fun _ -> ( + )) m 0
    let fold f = EltMap.fold (fun x n -> Array.fold_right f (Array.make n x))
    let min_elt m = fst (EltMap.min_binding m)
    let subset m1 m2 = EltMap.for_all (fun x n1 -> n1 <= count x m2) m1
    let inter m1 m2 = EltMap.merge (fun _ o1 o2 ->
      match o1, o2 with
      | None, _ | _, None -> None
      | Some n, Some m -> Some (min n m)) m1 m2
  end
end

module IntMultiSet = MultiSet.Make (struct
  type t = int
  let compare = compare
end)

module ClassMap = Map.Make (struct
  type t = PUnionFind.class_
  let compare = compare
end)

let () =
  let n, m = Scanf.scanf "%d %d\n" (fun n m -> n, m) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  let xys = Array.init m (fun _ -> Scanf.scanf "%d %d\n" (fun x y -> x, y)) in
  let u = Array.fold_left (fun u (x, y) -> PUnionFind.union u x y) (PUnionFind.make n) xys in
  let m =
    Array.init n (fun i -> i)
    |> Array.fold_left (fun m i -> ClassMap.add (PUnionFind.find u i) (as_.(i) :: try ClassMap.find (PUnionFind.find u i) m with Not_found -> []) m) ClassMap.empty in
  try
    Array.init n (fun i -> (i, as_.(i)))
    |> Array.to_list
    |> List.sort (fun (_, w) (_, w') -> compare w w')
    |> List.fold_left (fun (acc, u, s) (i, a) ->
        if PUnionFind.find u 0 = PUnionFind.find u i then (acc, u, s)
        else
          let a' = IntMultiSet.min_elt s in
          acc + a + a',
          PUnionFind.union u 0 i,
          IntMultiSet.remove a (List.fold_right IntMultiSet.add (ClassMap.find (PUnionFind.find u i) m) (IntMultiSet.remove a' s)))
        (0, u, List.fold_right IntMultiSet.add (ClassMap.find (PUnionFind.find u 0) m) IntMultiSet.empty)
    |> (fun (acc, _, _) -> acc)
    |> Printf.printf "%d\n"
  with Not_found -> print_endline "Impossible"