def popcount(n): cnt = 0 while n: cnt += n & 1 n >>= 1 return cnt N, M = map(int, input().split()) A = [] for i in range(N): A.append(list(map(int, input().split()))) ans = 10 ** 18 for s in range(1 << (N + 2)): c = popcount(s) if c > M: continue seen = [[0] * N for i in range(N)] cnt = 0 for i in range(N): for j in range(N): if (s >> i) & 1: seen[i][j] = 1 cnt += A[i][j] continue if (s >> N) & 1 and i == j: seen[i][j] = 1 cnt += A[i][j] continue if (s >> (N + 1)) & 1 and i + j == N - 1: seen[i][j] = 1 cnt += A[i][j] continue L = [0] * N for i in range(N): for j in range(N): if seen[i][j]: continue L[j] += A[i][j] L.sort() ans = min(ans, cnt + sum(L[:M-c])) print(ans)