from itertools import combinations N, M = map(int, input().split()) RowSum = [] A = [] for _ in range(N): l = list(map(int, input().split())) A.append(l) RowSum.append(sum(l)) RowBit = [] for i in range(1 << N): cnt = 0 row = [] for j in range(N): if (i & (1 << j)) != 0: row.append(j) cnt += RowSum[j] RowBit.append((row, cnt)) ans = [] for row, cnt in RowBit: if len(row) > M: continue elif len(row) == M: ans.append(cnt) else: for comb in combinations(range(N+2), M-len(row)): n = 0 for c in comb: if c == N: for i in range(N): if i not in row and i not in comb: n += A[i][i] elif c == N+1: for i in range(N): if i not in row and i not in comb and ((N not in comb) or i != N-1-i): n += A[i][N-1-i] else: for i in range(N): if i not in row: n += A[i][c] ans.append(cnt+n) print(min(ans))