import itertools from copy import deepcopy N, M = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(N)] def make_table(t, slash, backslash): table = deepcopy(A) solved = 0 for y, b in enumerate(t): if b: for x in range(N): solved += table[y][x] table[y][x] = 0 if slash: for i in range(N): solved += table[i][i] table[i][i] = 0 if backslash: for i in range(N): solved += table[N - i - 1][i] table[N - i - 1][i] = 0 return table, solved ans = 100 * N * N # 横と斜めは全列挙 for t in itertools.product((0, 1), repeat=N): row = t.count(1) if row > M: continue for slash, backslash in itertools.product((0, 1), repeat=2): col = M - row - slash - backslash # 削るべき列数 if not 0 <= col <= N: continue table, solved = make_table(t, slash, backslash) additional_solved = [0] * N # 縦のうれしい順に選ぶ for i in range(N): additional_solved[i] = sum(table[j][i] for j in range(N)) additional_solved.sort() solved += sum(additional_solved[:col]) ans = min(ans, solved) print(ans)