n,m = map(int,input().split()) a = [list(map(int,input().split())) for _ in range(n)] N = (1<<(n+2)) cnt = [0]*N for i in range(n+2): for j in range(1< m: continue res = [0]*n val = 0 for i in range(n): for j in range(n): if mask>>j&1 or (j == i and mask>>n&1) or (j == n-1-i and mask>>(n+1)&1): val += a[i][j] else: res[i] += a[i][j] res.sort() val += sum(res[:m-cm]) ans = min(ans,val) print(ans)