n,m = map(int,input().split()) A = [list(map(int,input().split())) for i in range(n)] ans = 10**10 for i in range(1<<(n+2)): s = [[1]*n for i in range(n)] count = 0 c = 0 for j in range(n+2): if i >> j & 1: c += 1 if j == n: for k in range(n): count += A[k][k] s[k][k] = 0 elif j == n+1: for k in range(n): count += A[k][-1-k] s[k][-1-k] = 0 else: for k in range(n): count += A[k][j] s[k][j] = 0 l = [] for i in range(n): l.append(sum([A[i][j]*s[i][j] for j in range(n)])) l.sort() now = 0 if c+n < m: continue while c < m: c += 1 count += l[now] now += 1 ans = min(ans,count) print(ans)