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

heaviest_child_weight = Hash.new(0)
leafs = (2..n).select {|u| g[u].size == 1}
until leafs.empty?
    v = leafs.pop
    if w = heaviest_child_weight[v]
        weight[v] += w
    end
    u = g[v].to_a[0]
    hcw = heaviest_child_weight[u]
    heaviest_child_weight[u] = weight[v] if weight[v] > hcw
    g[u].delete(v)
    leafs << u if u != 1 && g[u].size == 1
    heaviest_child_weight.delete(v)
    weight.delete(v)
end

p (weight.values.inject(:+) || 0) + (heaviest_child_weight.values.max || 0)