loop do
    n = gets.to_i
    break if n == 0
    t = n.times.map{gets.split.map(&:to_i)}
    dp = Array.new(1 << n, Float::INFINITY)
    dp[0] = 0
    (1 << n).times do |bit|
        n.times do |i|
            next if bit & (1 << i) != 0
            cost = t[i][0]
            n.times do |j|
                next if bit & (1 << j) == 0
                cost = t[i][j+1] if t[i][j+1] < cost
            end
            k = bit | (1 << i)
            dp[k] = dp[bit] + cost if dp[bit] + cost < dp[k]
        end
    end
    puts dp[(1<<n) - 1]
end