#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
inline char gc() {
  static char buf[1000000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  register long long x = 0, f = 1;
  register char c = gc();
  for (; !isdigit(c); c = gc())
    if (c == '-') f = -1;
  for (; isdigit(c); c = gc()) x = (x << 1) + (x << 3) + (c ^ 48);
  return x * f;
}
void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
void writeln(long long x) {
  write(x);
  puts("");
}
const int maxn = 4004;
pair<long long, int> f[maxn];
int front, rear, q[maxn];
int n, k;
int sum[maxn][maxn];
inline int calc(int i, int j) { return sum[j][j] - sum[j][i]; }
inline int slop(int a, int b) {
  int l = b, r = n, ans = b;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (f[a].first + calc(a, mid) < f[b].first + calc(b, mid)) {
      ans = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  return ans;
}
inline pair<long long, int> check(long long more) {
  front = rear = 0;
  f[0] = make_pair(0, 0);
  front = rear = 0;
  q[rear++] = 0;
  for (register int i = (1); i <= int(n); ++i) {
    while (rear - front >= 2 && (f[q[front]].first + calc(q[front], i) >=
                                 f[q[front + 1]].first + calc(q[front + 1], i)))
      front++;
    f[i].first = f[q[front]].first + calc(q[front], i) + more;
    f[i].second = f[q[front]].second + 1;
    while (rear - front >= 2 &&
           slop(q[rear - 2], q[rear - 1]) > slop(q[rear - 1], i))
      rear--;
    q[rear++] = i;
  }
  return f[n];
}
int a[maxn];
int main() {
  n = read(), k = read();
  char c = ' ';
  for (register int i = (1); i <= int(n); ++i) {
    for (register int j = (1); j <= int(i - 1); ++j) {
      c = gc();
      while (c == ' ' || c == '\n') c = gc();
      if (gc() == '0')
        sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + 10,
        gc();
      else
        sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + c - '0';
    }
    for (register int j = (i); j <= int(n); ++j) {
      c = gc();
      while (c == ' ' || c == '\n') c = gc();
      if (gc() == '0') gc();
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
    }
  }
  int l = 0, r = 1e9;
  long long ans = 0;
  while (l <= r) {
    long long mid = (l + r) / 2;
    pair<long long, int> tmp = check(mid);
    if (tmp.second >= k) {
      ans = tmp.first - k * mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  writeln(ans);
  return 0;
}
