require 'set'
n, m = gets.split.map(&:to_i)
weight = Hash[* (1..n).zip(gets.split.map(&:to_i)).flatten]
g = {}
(1..m).each do
    u, v = gets.split.map(&:to_i)
    (g[u] ||= Set.new) << v
    (g[v] ||= Set.new) << u
end

buckets = (1..m).map { Set.new }
(2..n).map do |u|
    buckets[g[u].size] << u
end

heaviest_child_weight = {}
until buckets[1].empty?
    v = buckets[1].to_a[0]
    buckets[1].delete(v)
    if w = heaviest_child_weight[v]
        weight[v] += w
    end
    u = g[v].to_a[0]
    hcw = (heaviest_child_weight[u] ||= 0)
    heaviest_child_weight[u] = weight[v] if weight[v] > hcw
    g.delete(v)
    buckets[g[u].size].delete(u)
    g[u].delete(v)
    buckets[g[u].size] << u
    heaviest_child_weight.delete(v)
    weight.delete(v)
end

p weight.values.inject(:+) + heaviest_child_weight.values.inject(:+)