N,M = map(int,input().split()) A = [list(map(int,input().split())) for _ in range(N)] ans = 10**5 for i in range(1<>k & 1: n += 1 for j in range(N): tot += A[k][j] if n>M:continue B = [] for j in range(N): cnt = 0 for k in range(N): if i>>k & 1:continue cnt += A[k][j] B.append(cnt) B = sorted(B) for j in range(M-n): tot += B[j] ans = min(ans,tot) tot = 0 for i in range(N): tot += A[i][i] if M==1: ans = min(ans,tot) else: for i in range(1<>k & 1: n += 1 for j in range(N): if j==k:continue tot1 += A[k][j] if n>M:continue B = [] for j in range(N): cnt = 0 for k in range(N): if i>>k & 1:continue if k==j:continue cnt += A[k][j] B.append(cnt) B = sorted(B) for j in range(M-n): tot1 += B[j] ans = min(ans,tot1) tot = 0 for i in range(N): tot += A[i][N-1-i] if M==1: ans = min(ans,tot) else: for i in range(1<>k & 1: n += 1 for j in range(N): if j==N-1-k:continue tot1 += A[k][j] if n>M:continue B = [] for j in range(N): cnt = 0 for k in range(N): if i>>k & 1:continue if k==N-1-j:continue cnt += A[k][j] B.append(cnt) B = sorted(B) for j in range(M-n): tot1 += B[j] ans = min(ans,tot1) if M>=2: tot = 0 for i in range(N): tot += A[i][i]+A[i][N-1-i] if N%2==1: tot -= A[N//2][N//2] if M==2: ans = min(ans,tot) else: for i in range(1<>k & 1: n += 1 for j in range(N): if j==k or j==N-1-k:continue tot1 += A[k][j] if n>M:continue B = [] for j in range(N): cnt = 0 for k in range(N): if i>>k & 1:continue if k==j or k==N-1-j:continue cnt += A[k][j] B.append(cnt) B = sorted(B) for j in range(M-n): tot1 += B[j] ans = min(ans,tot1) print(ans)