#include <bits/stdc++.h>
using namespace std;
int getnum() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 4010;
int n, k;
int s[N][N];
int F[N];
int G[N];
struct tnode {
  int l, r, x;
} Q[N];
void get_read() {
  n = getnum();
  k = getnum();
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) {
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + getnum();
    }
}
int trans(int i, int j, int C) {
  return F[j] + (s[i][i] + s[j][j] - s[i][j] * 2) / 2 + C;
}
void calc(int C) {
  int h = 1, t = 1;
  Q[1] = (tnode){1, n, 0};
  for (int i = 1; i <= n; ++i) {
    while (h < t && Q[h].r < i) ++h;
    F[i] = trans(i, Q[h].x, C);
    G[i] = G[Q[h].x] + 1;
    while (h < t && i >= Q[h].r) ++h;
    if (trans(n, Q[t].x, C) <= trans(n, i, C)) continue;
    while (h < t && trans(Q[t].l, Q[t].x, C) > trans(Q[t].l, i, C)) --t;
    int l = Q[t].l, r = Q[t].r, ret = Q[t].r + 1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (trans(mid, Q[t].x, C) > trans(mid, i, C))
        ret = mid, r = mid - 1;
      else
        l = mid + 1;
    }
    if (ret > n) continue;
    Q[t].r = ret - 1;
    Q[++t] = (tnode){ret, n, i};
  }
}
void get_work() {
  int l = 0, r = s[n][n], ans;
  while (l <= r) {
    int mid = (l + r) >> 1;
    calc(mid);
    if (G[n] <= k) {
      r = mid - 1;
      ans = F[n] - mid * k;
    } else
      l = mid + 1;
  }
  cout << ans;
}
signed main() {
  get_read();
  get_work();
  return 0;
}
