#include <bits/stdc++.h>
using namespace std;
template <class t>
struct rge {
  t h, n;
};
template <class t>
rge<t> range(t h, t n) {
  return rge<t>{h, n};
}
template <class t>
auto dud(t *r) -> decltype(cerr << *r, 2);
template <class t>
char dud(...);
struct debug {
  template <class t>
  debug &operator<<(const t &) {
    return *this;
  }
};
const int MN = 1 << 11;
char in[MN][MN];
int dp[MN][MN];
int n, k;
template <class t>
void maxi(t &x, t y) {
  if (x < y) x = y;
}
template <class t>
void mini(t &x, t y) {
  if (x > y) x = y;
}
void fill() {
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) {
      dp[i][j] = 0;
      if (i) maxi(dp[i][j], dp[i - 1][j]);
      if (j) maxi(dp[i][j], dp[i][j - 1]);
      dp[i][j] += (in[i][j] == 'a');
    }
}
int hashi[MN][MN];
int main() {
  scanf("%d%d", &n, &k);
  if (k >= 2 * n - 1) {
    for (int i = 0; i < 2 * n - 1; ++i) putchar('a');
    printf("\n");
    return 0;
  }
  k = min(k, 2 * n - 1);
  for (int i = 0; i < n; ++i) scanf("%s", in[i]);
  fill();
  for (int i = 0; i < n; ++i)
    debug() << __FUNCTION__ << "#" << 76 << ": "
            << "["
               "i"
               ": "
            << (i) << "] " << range(dp[i], dp[i] + n);
  int as = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (i + j + 1 - dp[i][j] <= k) maxi(as, i + j + 1);
  debug() << __FUNCTION__ << "#" << 81 << ": "
          << "["
             "as"
             ": "
          << (as) << "] ";
  if (as == 2 * n - 1) {
    for (int i = 0; i < 2 * n - 1; ++i) putchar('a');
    printf("\n");
    return 0;
  }
  hashi[n - 1][n - 1] = 0;
  for (int sum = 2 * n - 3; sum >= 0; --sum) {
    map<int, vector<pair<int, int> > > seen;
    for (int i = 0; i < n; ++i) {
      int j = sum - i;
      if (j < 0 || j >= n) continue;
      int suf_hash = 1e9;
      if (i < n - 1) mini(suf_hash, hashi[i + 1][j]);
      if (j < n - 1) mini(suf_hash, hashi[i][j + 1]);
      debug() << __FUNCTION__ << "#" << 96 << ": "
              << "["
                 "i"
                 ": "
              << (i)
              << "] "
                 "["
                 "j"
                 ": "
              << (j)
              << "] "
                 "["
                 "suf_hash"
                 ": "
              << (suf_hash) << "] ";
      int my_hash = in[i][j] * 1000000 + suf_hash;
      seen[my_hash].emplace_back(i, j);
    }
    debug() << __FUNCTION__ << "#" << 101 << ": "
            << "["
               "seen"
               ": "
            << (seen) << "] ";
    int cou = 0;
    for (auto &x : seen) {
      for (pair<int, int> y : x.second) hashi[y.first][y.second] = cou;
      cou++;
    }
  }
  for (int i = 0; i < n; ++i)
    debug() << __FUNCTION__ << "#" << 109 << ": "
            << "["
               "i"
               ": "
            << (i) << "] " << range(hashi[i], hashi[i] + n);
  pair<int, pair<int, int> > start;
  start.first = 1e9;
  for (int i = 0; i < n; ++i) {
    int j = as - i - 1;
    if (j < 0 || j >= n) continue;
    if (i + j + 1 - dp[i][j] <= k) {
      debug() << __FUNCTION__ << "#" << 116 << ": "
              << "["
                 "i"
                 ": "
              << (i)
              << "] "
                 "["
                 "j"
                 ": "
              << (j) << "] ";
      if (i != n - 1)
        mini(start, make_pair(hashi[i + 1][j], make_pair(i + 1, j)));
      if (j != n - 1)
        mini(start, make_pair(hashi[i][j + 1], make_pair(i, j + 1)));
    }
  }
  string ans(as, 'a');
  ans.push_back(in[start.second.first][start.second.second]);
  pair<int, int> pos = start.second;
  while (pos != make_pair(n - 1, n - 1)) {
    if (pos.second == n - 1)
      pos.first++;
    else if (pos.first == n - 1)
      pos.second++;
    else {
      if (hashi[pos.first + 1][pos.second] < hashi[pos.first][pos.second + 1])
        pos.first++;
      else
        pos.second++;
    }
    ans.push_back(in[pos.first][pos.second]);
  }
  printf("%s\n", ans.c_str());
}
