import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Stack; import java.util.Scanner; public class No1345 { private static List> combination(List list, int count) { List ret = new ArrayList>(); for (int i=0; i < list.size(); i++) { if (i + count > list.size()) { break; } Stack stack = new Stack(); stack.push(list.get(i)); _combination(ret, list, stack, i+1, count); } return ret; } private static void _combination(List ret, List list, Stack stack, int index, int count) { for (int i=index; i < list.size(); i++) { stack.push(list.get(i)); if (stack.size() == count) { ret.add(Arrays.asList(stack.toArray())); stack.pop(); continue; } _combination(ret, list, stack, i+1, count); stack.pop(); } } private static class Row { public List row; public int cnt; public Row() { row = new ArrayList(); cnt = 0; } } public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int M = scan.nextInt(); int[] RowSum = new int[N]; int[][] A = new int[N][N]; for (int i=0; i < N; i++) { int sum = 0; for (int j=0; j < N; j++) { int a = scan.nextInt(); sum += a; A[i][j] = a; } RowSum[i] = sum; } Row[] RowBlt = new Row[1< Range = new ArrayList(); for (int i=0; i < N+2; i++) { Range.add(i); } int ans = Integer.MAX_VALUE; for (Row row : RowBlt) { if (row.row.size() > M) { continue; } else if (row.row.size() == M) { ans = Math.min(ans, row.cnt); } else { for (List comb : combination(Range, M-row.row.size())) { int n = 0; for (int c : comb) { if (c == N) { for (int i=0; i < N; i++) { if (!row.row.contains(i) && !comb.contains(i)) { n += A[i][i]; } } } else if (c == N+1) { for (int i=0; i < N; i++) { if (!row.row.contains(i) && !comb.contains(N-1-i) && !(comb.contains(N) && i == N-1-i)) { n += A[i][N-1-i]; } } } else { for (int i=0; i < N; i++) { if (!row.row.contains(i)) { n += A[i][c]; } } } } ans = Math.min(ans, row.cnt + n); } } } System.out.println(ans); } }