loop do
  n = gets.chomp.to_i

  if n == 0
    break
  end

  t = Array.new(n) { Array.new(n + 1) }
  
  n.times do |i|
    t[i] = gets.chomp.split.map(&:to_i)
  end

  dp = Array.new(1 << n)

  (1 << n).times do |i|
    dp[i] = 1000000000
  end
  dp[0] = 0

  (1 << n).times do |i|
    n.times do |j|
      tt = []
      n.times do |k|
        tt.push(((i >> k) & 1) == 1 ? t[j][k + 1] : t[j][0])
      end
      dp[i | (1 << j)] = [dp[i | (1 << j)], dp[i] + tt.min].min
    end
  end

  puts dp[(1 << n) - 1]

end
    
 