

loop do
  sn, dn = gets.split.map(&:to_i)
  break if sn == 0 && dn == 0

  sdn = dn + 1

  edges = []

  sn.times do
    ds = gets.split.map(&:to_i)
    for j in (0...dn)
      d = ds.shift
      if d > 0
        edges << [d, 0, j + 1, false]
      end
    end
  end

  for i in (1..(dn - 1))
    ds = gets.split.map(&:to_i)
    for j in ((i + 1)..dn)
      d = ds.shift
      if d > 0
        edges << [d, i, j, false]
        edges << [d, j, i, false]
      end
    end
  end

  edges.sort!
  #p edges

  used = [true] + dn.times.map{false}
  nused = 1
  dsum = 0

  while nused < sdn
    for e in edges
      d, i, j = e
      if used[i]
        e[3] = true
        if !used[j]
          used[j] = true
          nused += 1
          dsum += d
          break
        end
      end
    end

    edges.delete_if{|e| e[3]}
  end

  p dsum
end