N,M = map(int,input().split()) A = [list(map(int,input().split())) for i in range(N)] res = 10**18 for i in range(2**(N+2)): tmp_A = [[A[j][k] for k in range(N)] for j in range(N)] cost = 0 cnt = M for j in range(N): if i>>j & 1: for k in range(N): cost += tmp_A[j][k] tmp_A[j][k] = 0 cnt -= 1 if i>>(N) & 1: for k in range(N): cost += tmp_A[k][k] tmp_A[k][k] = 0 cnt -= 1 if i>>(N+1) & 1: for k in range(N): cost += tmp_A[N-1-k][k] tmp_A[N-1-k][k] = 0 cnt -= 1 column = [sum(tmp_A[k][j] for k in range(N)) for j in range(N)] column.sort() cost += sum(column[:cnt]) res = min(res,cost) print(res)