from copy import deepcopy 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 = deepcopy(A) 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 += s[k][k] s[k][k] = 0 elif j == n+1: for k in range(n): count += s[k][-1-k] s[k][-1-k] = 0 else: for k in range(n): count += s[k][j] s[k][j] = 0 l = [sum(s[i]) for i 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)