#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
template <typename first, typename second>
ostream& operator<<(ostream& os, const pair<first, second>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ",";
    os << *it;
  }
  return os << "]";
}
template <typename T>
ostream& operator<<(ostream& os, const multiset<T>& v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename first, typename second>
ostream& operator<<(ostream& os, const map<first, second>& v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << it->first << " = " << it->second;
  }
  return os << "]";
}
void faltu() { cerr << '\n'; }
template <typename T>
void faltu(T a[], int n) {
  for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
  cerr << '\n';
}
template <typename T, typename... hello>
void faltu(T arg, const hello&... rest) {
  cerr << arg << ' ';
  faltu(rest...);
}
int n, k;
int a[4005];
int C[4005][4005];
long long dp[2][4005];
int U[4005][4005];
void compute(int idx, int l, int r, int optl, int optr) {
  if (l > r) return;
  int mid = (l + r) >> 1;
  pair<long long, int> best = {-infLL, -inf};
  for (int k = optl; k <= min(mid - 1, optr); k++) {
    best = max(best, make_pair(dp[idx ^ 1][k] + C[k + 1][mid], -k));
  }
  dp[idx][mid] = best.first;
  int opt = -best.second;
  compute(idx, l, mid - 1, optl, opt);
  compute(idx, mid + 1, r, opt, optr);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      cin >> U[i][j];
      U[i][j] *= -1;
    }
  }
  for (int i = n; i >= 1; --i) {
    for (int j = i; j <= n; ++j) {
      C[i][j] = C[i + 1][j] + C[i][j - 1] - C[i + 1][j - 1] + U[i][j];
    }
  }
  dp[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    dp[0][i] = -infLL;
  }
  for (int i = 1; i <= k; ++i) {
    compute(i % 2, i, n, i - 1, n);
  }
  cout << -dp[k % 2][n] << '\n';
}
