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|
      if (i >> j) & 1 == 1
        next
      end
      minT  = t[j][0]
      n.times do |k|
        if (i >> k) & 1 == 1 && minT > t[j][k + 1]
          minT = t[j][k + 1]
        end
      end
      # if dp[i | (1 << j)] > dp[i] + minT
      #   dp[i | (1 << j)] = dp[i] + minT
      # end
    end
  end

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