#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#define debug(x) //std::cerr << #x << " = " << (x) << std::endl
using namespace std;
typedef long long LL;
const int MAXN = 2e3 + 17;
const int MOD = 998244353;
int n,vis[MAXN][MAXN],k;
char mp[MAXN][MAXN];
string f[MAXN][MAXN],ans;
void dfs(int x,int y)
{
	debug(x);
	debug(y);
	debug(ans);
	if(x==n-1&&y==n-1)
	{
		return ;
	}
	else if(x==n-1)
	{
		ans.push_back(mp[x][y+1]);
		dfs(x,y+1);
	}
	else if(y==n-1)
	{
		ans.push_back(mp[x+1][y]);
		dfs(x+1,y);
	}
	else
	{
		if(mp[x][y+1]<mp[x+1][y])
		{
			ans.push_back(mp[x][y+1]);
			dfs(x,y+1);
		}
		else if(mp[x][y+1]>mp[x+1][y])
		{
			ans.push_back(mp[x+1][y]);
			dfs(x+1,y);
		}
		else
		{
			debug(x);
			debug(y);
			ans.push_back(mp[x+1][y]);
			int sum = 0,sx,sy;
			queue<pair<int,int > > que;
			que.push({x,y+1});
			que.push({x+1,y});
			while(que.size()>1)
			{
				queue<pair<int,int > > nque;
				char mn = 'z'+1;
				int sum = 0;
				while(que.size())
				{
					auto now = que.front();
					que.pop();
					int tx = now.first,ty = now.second;
					if(tx+1<n&&!vis[tx+1][ty])
					{
						vis[tx+1][ty] = 1;
						if(mp[tx+1][ty]<=mn)
						{
							debug(mp[tx+1][ty]);
							nque.push({tx+1,ty});
							if(mp[tx+1][ty]!=mn)
								sum = 0,sx = tx+1,sy = ty;
							mn = mp[tx+1][ty];
							++sum;
						}
					}
					if(ty+1<n&&vis[tx][ty+1]!=1)
					{
						vis[tx][ty+1] = 1;
						if(mp[tx][ty+1]<=mn)
						{
							debug(mp[tx][ty+1]);
							nque.push({tx,ty+1});
							if(mp[tx][ty+1]!=mn)
								sum = 0,sx = tx,sy = ty+1;
							mn = mp[tx][ty+1];
							++sum;
						}
					}
				}
				debug(mn);
				ans.push_back(mn);
				if(sum==1) break;
				while(!nque.empty())
				{
					auto now = nque.front();
					nque.pop();
					if(mp[now.first][now.second]==mn)
						que.push(now);
				}
			}
			dfs(sx,sy);
		}
	}
}
int main(int argc, char const *argv[])
{
#ifdef noob
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
	cin>>n>>k;
	for (int i = 0; i < n; i++)
	{
		cin>>mp[i];
	}
	ans.push_back(mp[0][0]);
	dfs(0,0);
	debug(ans);
	for(auto & i: ans)
	{
		if(k&&i!='a') i = 'a',--k;
	}
	cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#define debug(x) //std::cerr << #x << " = " << (x) << std::endl
using namespace std;
typedef long long LL;
const int MAXN = 2e3 + 17;
const int MOD = 998244353;
int n,vis[MAXN][MAXN],k;
pair<int,int > dir[MAXN][MAXN];
char mp[MAXN][MAXN];
string f[MAXN][MAXN];
string dfs(int x,int y)
{
	string nil = "";
	nil.push_back(mp[x][y]);
	if(vis[x][y])
	{
		if(x==n-1&&y==n-1)
			return nil;
		else
			return nil+dfs(x+dir[x][y].first,y+dir[x][y].second);
	}
	vis[x][y] = 1;
	if(x==n-1&&y==n-1)
	{
		return nil;
	}
	else if(x==n-1)
	{
		nil = nil + dfs(x,y+1);
		dir[x][y].first = 0,dir[x][y].second = 1;
	}
	else if(y==n-1)
	{
		nil = nil + dfs(x+1,y);
		dir[x][y].first = 1,dir[x][y].second = 0;
	}
	else
	{
		string s1 = dfs(x+1,y);
		string s2 = dfs(x,y+1);

		if(mp[x][y+1]<mp[x+1][y])
		{
			nil = nil + s2;
			dir[x][y].first = 0,dir[x][y].second = 1;
		}
		else if(mp[x][y+1]>mp[x+1][y])
		{
			nil = nil + s1;
			dir[x][y].first = 1,dir[x][y].second = 0;
		}
		else
		{
			if(s1<s2)
			{
				nil = nil + s1;
				dir[x][y].first = 1,dir[x][y].second = 0;
			}
			else
			{
				nil = nil + s2;
				dir[x][y].first = 0,dir[x][y].second = 1;
			}
		}
		if(x==2&&y==0)
		{
			debug(s1);
			debug(s2);
			debug(nil);
		}
	}
	// debug(x);
	// debug(y);
	// debug(dir[x][y].first);
	// debug(dir[x][y].second);
	return nil;
}
int main(int argc, char const *argv[])
{
#ifdef noob
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
	cin>>n>>k;
	for (int i = 0; i < n; i++)
	{
		cin>>mp[i];
	}
	string ans = dfs(0,0);
	debug(ans);
	for(auto & i: ans)
	{
		if(k&&i!='a') i = 'a',--k;
	}
	cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#define debug(x) //std::cerr << #x << " = " << (x) << std::endl
using namespace std;
typedef long long LL;
const int MAXN = 2e3 + 17;
const int MOD = 998244353;
int n,vis[MAXN][MAXN],k;
char mp[MAXN][MAXN];
string f[MAXN][MAXN],ans;
void dfs(int x,int y)
{
	debug(x);
	debug(y);
	debug(ans);
	if(x==n-1&&y==n-1)
	{
		return ;
	}
	else if(x==n-1)
	{
		ans.push_back(mp[x][y+1]);
		dfs(x,y+1);
	}
	else if(y==n-1)
	{
		ans.push_back(mp[x+1][y]);
		dfs(x+1,y);
	}
	else
	{
		if(mp[x][y+1]<mp[x+1][y])
		{
			ans.push_back(mp[x][y+1]);
			dfs(x,y+1);
		}
		else if(mp[x][y+1]>mp[x+1][y])
		{
			ans.push_back(mp[x+1][y]);
			dfs(x+1,y);
		}
		else
		{
			debug(x);
			debug(y);
			ans.push_back(mp[x+1][y]);
			int sum = 0,sx,sy,ls = x+y+1;
			queue<pair<int,int > > que;
			que.push({x,y+1});
			que.push({x+1,y});
			while(que.size()>1)
			{
				queue<pair<int,int > > nque;
				char mn = 117;
				int sum = 0;
				while(que.size())
				{
					auto now = que.front();
					que.pop();
					int tx = now.first,ty = now.second;
					if(tx+1<n&&!vis[tx+1][ty])
					{
						vis[tx+1][ty] = 1;
						if(mp[tx+1][ty]<=mn)
						{
							debug(mp[tx+1][ty]);
							nque.push({tx+1,ty});
							if(mp[tx+1][ty]!=mn)
								sum = 0,sx = tx+1,sy = ty;
							mn = mp[tx+1][ty];
							++sum;
						}
					}
					if(ty+1<n&&vis[tx][ty+1]!=1)
					{
						vis[tx][ty+1] = 1;
						if(mp[tx][ty+1]<=mn)
						{
							debug(mp[tx][ty+1]);
							nque.push({tx,ty+1});
							if(mp[tx][ty+1]!=mn)
								sum = 0,sx = tx,sy = ty+1;
							mn = mp[tx][ty+1];
							++sum;
						}
					}
				}
				debug(mn);
				ans.push_back(mn);
				if(sum==1) break;
				while(!nque.empty())
				{
					auto now = nque.front();
					nque.pop();
					if(mp[now.first][now.second]==mn)
						que.push(now);
				}
			}
			dfs(sx,sy);
		}
	}
}
int main(int argc, char const *argv[])
{
#ifdef noob
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
	cin>>n>>k;
	for (int i = 0; i < n; i++)
	{
		cin>>mp[i];
	}
	ans.push_back(mp[0][0]);
	dfs(0,0);
	debug(ans);
	for(auto & i: ans)
	{
		if(k&&i!='a') i = 'a',--k;
	}
	cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define per(i, j, n) for (int i = n; i > j; --i)
#define fase_read_init                                                                             \
	const int MAXS = 32 * 1024 * 1024;                                                         \
	char buf[MAXS], *ch;
#define read(x)                                                                                \
	while (*ch <= 32) ++ch;                                                                    \
	for (x = 0; *ch >= '0'; ++ch) x = x * 10 + *ch - '0';
#define read_init                                                                                \
	ch = buf - 1;                                                                              \
	fread(buf, 1, MAXS, stdin);
#define SIZE(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define LL ((l + r) >> 1)
#define RR (LL + 1)
#define chutzpah 1
#ifdef chutzpah
template <class T> ostream &operator<<(ostream &os, const vector<T> &t) {
	os << "{";
	for (auto &i : t) os << i << ",";
	os << "\b}";
	return os;
}
template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &t) {
	return os << "(" << t.first << "," << t.second << ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
	cerr << " " << H;
	debug_out(T...);
}
#define dbg(...)                                                                                \
	cerr << "#" << setw(3) << setiosflags(ios::left) << __LINE__ << "[" << #__VA_ARGS__ "]:",  \
	    debug_out(__VA_ARGS__);
#else
#define dbg(...) 42
#endif
template <class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template <class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const double EPS = 1e-8;
const int INF    = 0x3f3f3f3f;
const int MOD    = (int)1e9 + 7;
const int MAXN   = (int)2e3 + 5;

char s[MAXN][MAXN];
typedef map<pii, pair<char, int>> SET;
pair<char, int> d[MAXN][MAXN];

pair<char, int> f(int x, int y, int k) {
	if (s[x][y] != 'a' && k != 0) return make_pair('a', k + 1);
	return make_pair(s[x][y], k);
}

int main() {
	int n, k;
	cin >> n >> k;
	rep(i, 0, n) scanf("%s", s[i]);
	string ans;
	vector<pii> a[2];
	rep(i, 0, n) rep(j, 0, n) d[i][j] = make_pair('z' + 1, 0);
	d[0][0] = f(0, 0, -k);
	ans += d[0][0].first;
	a[0].push_back(pii(0, 0));
	char mic[2] = {d[0][0].first, 'z'};
	rep(i, 2, (n << 1)) {
		a[~i & 1].clear();
		mic[~i & 1] = 'z';
		// dbg(i, a[i & 1].size());
		for (auto &v : a[i & 1]) {
			//dbg(mic[i&1], v.first, v.second);
			if (mic[i & 1] < d[v.first][v.second].first) continue;
			pii vv[2] = {v, v};
			vv[0].first += 1;
			vv[1].second += 1;
			pair<char, int> e[2];
			rep(j, 0, 2) {
				if (vv[j].first < n && vv[j].second < n) {
					e[j] = f(vv[j].first, vv[j].second, d[v.first][v.second].second);
					if(d[vv[j].first][vv[j].second].first > 'z') a[~i & 1].push_back(vv[j]);
					if (MN(d[vv[j].first][vv[j].second], e[j])) {
						MN(mic[~i & 1], e[j].first);
					}
				}
			}
		}
		// dbg(minc);
		ans += mic[~i & 1];
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define per(i, j, n) for (int i = n; i > j; --i)
#define fase_read_init                                                                             \
	const int MAXS = 32 * 1024 * 1024;                                                         \
	char buf[MAXS], *ch;
#define read(x)                                                                                \
	while (*ch <= 32) ++ch;                                                                    \
	for (x = 0; *ch >= '0'; ++ch) x = x * 10 + *ch - '0';
#define read_init                                                                                \
	ch = buf - 1;                                                                              \
	fread(buf, 1, MAXS, stdin);
#define SIZE(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define LL ((l + r) >> 1)
#define RR (LL + 1)
#define chutzpah 1
#ifdef chutzpah
template <class T> ostream &operator<<(ostream &os, const vector<T> &t) {
	os << "{";
	for (auto &i : t) os << i << ",";
	os << "\b}";
	return os;
}
template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &t) {
	return os << "(" << t.first << "," << t.second << ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
	cerr << " " << H;
	debug_out(T...);
}
#define dbg(...)                                                                                \
	cerr << "#" << setw(3) << setiosflags(ios::left) << __LINE__ << "[" << #__VA_ARGS__ "]:",  \
	    debug_out(__VA_ARGS__);
#else
#define dbg(...) 42
#endif
template <class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template <class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const double EPS = 1e-8;
const int INF    = 0x3f3f3f3f;
const int MOD    = (int)1e9 + 7;
const int MAXN   = (int)2e3 + 5;

char s[MAXN][MAXN];
typedef map<pii, pair<char, int>> SET;
pair<char, int> d[MAXN][MAXN];

pair<char, int> f(int x, int y, int k) {
	if (s[x][y] != 'a' && k != 0) return make_pair('a', k + 1);
	return make_pair(s[x][y], k);
}

int main() {
	int n, k;
	cin >> n >> k;
	rep(i, 0, n) cin >> s[i];
	string ans;
	vector<pii> a[2];
	rep(i, 0, n) rep(j, 0, n) d[i][j] = make_pair('z' + 1, 0);
	d[0][0] = f(0, 0, -k);
	ans += d[0][0].first;
	a[0].push_back(pii(0, 0));
	char mic[2] = {d[0][0].first, 'z'};
	rep(i, 2, (n << 1)) {
		a[~i & 1].clear();
		mic[~i & 1] = 'z';
		// dbg(i, a[i & 1].size());
		for (auto &v : a[i & 1]) {
			//dbg(mic[i&1], v.first, v.second);
			if (mic[i & 1] < d[v.first][v.second].first) continue;
			pii vv[2] = {v, v};
			vv[0].first += 1;
			vv[1].second += 1;
			pair<char, int> e[2];
			rep(j, 0, 2) {
				if (vv[j].first < n && vv[j].second < n) {
					e[j] = f(vv[j].first, vv[j].second,
						 d[v.first][v.second].second);
					if (MN(d[vv[j].first][vv[j].second], e[j])) {
						a[~i & 1].push_back(vv[j]);
						MN(mic[~i & 1], e[j].first);
					}
				}
			}
		}
		// dbg(minc);
		ans += mic[~i & 1];
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define per(i, j, n) for (int i = n; i > j; --i)
#define fase_read_init                                                                             \
	const int MAXS = 32 * 1024 * 1024;                                                         \
	char buf[MAXS], *ch;
#define read(x)                                                                                \
	while (*ch <= 32) ++ch;                                                                    \
	for (x = 0; *ch >= '0'; ++ch) x = x * 10 + *ch - '0';
#define read_init                                                                                \
	ch = buf - 1;                                                                              \
	fread(buf, 1, MAXS, stdin);
#define SIZE(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define LL ((l + r) >> 1)
#define RR (LL + 1)
#define chutzpah 1
#ifdef chutzpah
template <class T> ostream &operator<<(ostream &os, const vector<T> &t) {
	os << "{";
	for (auto &i : t) os << i << ",";
	os << "\b}";
	return os;
}
template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &t) {
	return os << "(" << t.first << "," << t.second << ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
	cerr << " " << H;
	debug_out(T...);
}
#define dbg(...)                                                                                \
	cerr << "#" << setw(3) << setiosflags(ios::left) << __LINE__ << "[" << #__VA_ARGS__ "]:",  \
	    debug_out(__VA_ARGS__);
#else
#define dbg(...) 42
#endif
template <class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template <class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const double EPS = 1e-8;
const int INF    = 0x3f3f3f3f;
const int MOD    = (int)1e9 + 7;
const int MAXN   = (int)2e3 + 5;

char s[MAXN][MAXN];
typedef map<pii, pair<char, int>> SET;
pair<char, int> d[MAXN][MAXN];

pair<char, int> f(int x, int y, int k) {
	if (s[x][y] != 'a' && k != 0) return make_pair('a', k + 1);
	return make_pair(s[x][y], k);
}

int main() {
	int n, k;
	cin >> n >> k;
	rep(i, 0, n) cin >> s[i];
	string ans;
	vector<pii> a[2];
	rep(i, 0, n) rep(j, 0, n) d[i][j] = make_pair('z' + 1, 0);
	d[0][0] = f(0, 0, -k);
	ans += d[0][0].first;
	a[0].push_back(pii(0, 0));
	char mic[2] = {d[0][0].first, 'z'};
	rep(i, 2, (n << 1)) {
		a[~i & 1].clear();
		mic[~i & 1] = 'z';
		// dbg(i, a[i & 1].size());
		for (auto &v : a[i & 1]) {
			//dbg(mic[i&1], v.first, v.second);
			if (mic[i & 1] < d[v.first][v.second].first) continue;
			pii vv[2] = {v, v};
			vv[0].first += 1;
			vv[1].second += 1;
			pair<char, int> e[2];
			rep(j, 0, 2) {
				if (vv[j].first < n && vv[j].second < n) {
					e[j] = f(vv[j].first, vv[j].second, d[v.first][v.second].second);
					if(d[vv[j].first][vv[j].second].first > 'z') a[~i & 1].push_back(vv[j]);
					if (MN(d[vv[j].first][vv[j].second], e[j])) {
						MN(mic[~i & 1], e[j].first);
					}
				}
			}
		}
		// dbg(minc);
		ans += mic[~i & 1];
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define per(i, j, n) for (int i = n; i > j; --i)
#define fase_read_init                                                                             \
	const int MAXS = 32 * 1024 * 1024;                                                         \
	char buf[MAXS], *ch;
#define read(x)                                                                                \
	while (*ch <= 32) ++ch;                                                                    \
	for (x = 0; *ch >= '0'; ++ch) x = x * 10 + *ch - '0';
#define read_init                                                                                \
	ch = buf - 1;                                                                              \
	fread(buf, 1, MAXS, stdin);
#define SIZE(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define LL ((l + r) >> 1)
#define RR (LL + 1)
#define chutzpah 1
#ifdef chutzpah
template <class T> ostream &operator<<(ostream &os, const vector<T> &t) {
	os << "{";
	for (auto &i : t) os << i << ",";
	os << "\b}";
	return os;
}
template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &t) {
	return os << "(" << t.first << "," << t.second << ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
	cerr << " " << H;
	debug_out(T...);
}
#define dbg(...)                                                                                \
	cerr << "#" << setw(3) << setiosflags(ios::left) << __LINE__ << "[" << #__VA_ARGS__ "]:",  \
	    debug_out(__VA_ARGS__);
#else
#define dbg(...) 42
#endif
template <class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template <class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const double EPS = 1e-8;
const int INF    = 0x3f3f3f3f;
const int MOD    = (int)1e9 + 7;
const int MAXN   = (int)2e3 + 5;

char s[MAXN][MAXN];
typedef map<pii, pair<char, int>> SET;
pair<char, int> d[MAXN][MAXN];

pair<char, int> f(int x, int y, int k) {
	if (s[x][y] != 'a' && k != 0) return make_pair('a', k + 1);
	return make_pair(s[x][y], k);
}

int main() {
	int n, k;
	cin >> n >> k;
	rep(i, 0, n) cin >> s[i];
	string ans;
	vector<pii> a[2];
	rep(i, 0, n) rep(j, 0, n) d[i][j] = make_pair('z', 0);
	d[0][0] = f(0, 0, -k);
	ans += d[0][0].first;
	a[0].push_back(pii(0, 0));
	char mic[2] = {d[0][0].first, 'z'};
	rep(i, 2, (n << 1)) {
		a[~i & 1].clear();
		mic[~i & 1] = 'z';
		// dbg(i, a[i & 1].size());
		for (auto &v : a[i & 1]) {
			//dbg(mic[i&1], v.first, v.second);
			if (mic[i & 1] < d[v.first][v.second].first) continue;
			pii vv[2] = {v, v};
			vv[0].first += 1;
			vv[1].second += 1;
			pair<char, int> e[2];
			rep(j, 0, 2) {
				if (vv[j].first < n && vv[j].second < n) {
					e[j] = f(vv[j].first, vv[j].second,
						 d[v.first][v.second].second);
					if (MN(d[vv[j].first][vv[j].second], e[j])) {
						a[~i & 1].push_back(vv[j]);
						MN(mic[~i & 1], e[j].first);
					}
				}
			}
		}
		// dbg(minc);
		ans += mic[~i & 1];
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define per(i, j, n) for (int i = n; i > j; --i)
#define fase_read_init                                                                             \
	const int MAXS = 32 * 1024 * 1024;                                                         \
	char buf[MAXS], *ch;
#define read(x)                                                                                \
	while (*ch <= 32) ++ch;                                                                    \
	for (x = 0; *ch >= '0'; ++ch) x = x * 10 + *ch - '0';
#define read_init                                                                                \
	ch = buf - 1;                                                                              \
	fread(buf, 1, MAXS, stdin);
#define SIZE(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define LL ((l + r) >> 1)
#define RR (LL + 1)
#define chutzpah 1
#ifdef chutzpah
template <class T> ostream &operator<<(ostream &os, const vector<T> &t) {
	os << "{";
	for (auto &i : t) os << i << ",";
	os << "\b}";
	return os;
}
template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &t) {
	return os << "(" << t.first << "," << t.second << ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
	cerr << " " << H;
	debug_out(T...);
}
#define dbg(...)                                                                                \
	cerr << "#" << setw(3) << setiosflags(ios::left) << __LINE__ << "[" << #__VA_ARGS__ "]:",  \
	    debug_out(__VA_ARGS__);
#else
#define dbg(...) 42
#endif
template <class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template <class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const double EPS = 1e-8;
const int INF    = 0x3f3f3f3f;
const int MOD    = (int)1e9 + 7;
const int MAXN   = (int)2e3 + 5;

char s[MAXN][MAXN];
typedef map<pii, pair<char, int>> SET;
pair<char, int> d[MAXN][MAXN];

pair<char, int> f(int x, int y, int k) {
	if (s[x][y] != 'a' && k != 0) return make_pair('a', k + 1);
	return make_pair(s[x][y], k);
}

int main() {
	int n, k;
	cin >> n >> k;
	rep(i, 0, n) cin >> s[i];
	string ans;
	vector<pii> a[2];
	d[0][0] = f(0, 0, -k);
	ans += d[0][0].first;
	a[0].push_back(pii(0, 0));
	char mic[2] = {d[0][0].first, 'z'};
	rep(i, 0, n) rep(j, 0, n) d[i][j] = make_pair('z', 0);
	rep(i, 2, (n << 1)) {
		a[~i & 1].clear();
		mic[~i & 1] = 'z';
		// dbg(i, a[i & 1].size());
		for (auto &v : a[i & 1]) {
			// dbg(v.first, v.second);
			if (mic[i & 1] < d[v.first][v.second].first) continue;
			pii vv[2] = {v, v};
			vv[0].first += 1;
			vv[1].second += 1;
			pair<char, int> e[2];
			rep(j, 0, 2) {
				if (vv[j].first < n && vv[j].second) {
					e[j] = f(vv[j].first, vv[j].second,
						 d[v.first][v.second].second);
					if (MN(d[vv[j].first][vv[j].second], e[j])) {
						a[~i & 1].push_back(vv[j]);
					}
					MN(mic[~i & 1], e[j].first);
				}
			}
		}
		// dbg(minc);
		ans += mic[~i & 1];
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define per(i, j, n) for (int i = n; i > j; --i)
#define fase_read_init                                                                             \
	const int MAXS = 32 * 1024 * 1024;                                                         \
	char buf[MAXS], *ch;
#define read(x)                                                                                \
	while (*ch <= 32) ++ch;                                                                    \
	for (x = 0; *ch >= '0'; ++ch) x = x * 10 + *ch - '0';
#define read_init                                                                                \
	ch = buf - 1;                                                                              \
	fread(buf, 1, MAXS, stdin);
#define SIZE(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define LL ((l + r) >> 1)
#define RR (LL + 1)
#define chutzpah 1
#ifdef chutzpah
template <class T> ostream &operator<<(ostream &os, const vector<T> &t) {
	os << "{";
	for (auto &i : t) os << i << ",";
	os << "\b}";
	return os;
}
template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &t) {
	return os << "(" << t.first << "," << t.second << ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
	cerr << " " << H;
	debug_out(T...);
}
#define dbg(...)                                                                                \
	cerr << "#" << setw(3) << setiosflags(ios::left) << __LINE__ << "[" << #__VA_ARGS__ "]:",  \
	    debug_out(__VA_ARGS__);
#else
#define dbg(...) 42
#endif
template <class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template <class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const double EPS = 1e-8;
const int INF    = 0x3f3f3f3f;
const int MOD    = (int)1e9 + 7;
const int MAXN   = (int)2e3 + 5;

char s[MAXN][MAXN];
typedef map<pii, pair<char, int>> SET;

pair<char, int> f(int x, int y, int k) {
	if (s[x][y] != 'a' && k != 0) return make_pair('a', k + 1);
	return make_pair(s[x][y], k);
}

SET a[2];

int main() {
	int n, k;
	cin >> n >> k;
	rep(i, 0, n) cin >> s[i];
	string ans;
	if (s[0][0] != 'a' && k)
		a[0][pii(0, 0)] = make_pair('a', 1 - k), ans += 'a';
	else
		a[0][pii(0, 0)] = make_pair(s[0][0], -k), ans += s[0][0];
	char mic[2] = {a[0][pii(0, 0)].first, 'z'};
	rep(i, 2, (n << 1)) {
		a[~i & 1].clear();
		mic[~i&1] = 'z';
		//dbg(i, a[i & 1].size());
	   	for (auto &v : a[i & 1]) {
			//dbg(v.first, v.second);
			if (mic[i&1] < v.second.first) continue;
			pii v1 = v.first, v2 = v.first;
			v1.first += 1;
			v2.second += 1;
			pair<char, int> e1, e2;
			if (v1.first < n) {
				e1 = f(v1.first, v1.second, v.second.second);
				if (a[~i & 1].find(v1) == a[~i & 1].end()) {
					a[~i & 1][v1] = e1;
				} else {
					MN(a[~i & 1][v1], e1);
				}
				MN(mic[~i&1], e1.first);
			}
			if (v2.second < n) {
				e2 = f(v2.first, v2.second, v.second.second);
				if (a[~i & 1].find(v2) == a[~i & 1].end()) {
					a[~i & 1][v2] = e2;
				} else {
					MN(a[~i & 1][v2], e2);
				}
				MN(mic[~i&1], e2.first);
			}
		}
		//dbg(minc);
		ans += mic[~i&1];
	}
	cout << ans << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <time.h>
#include <sstream>
#include <string>
#include <fstream>
#include <functional>
#include <list>
#include <cstring>
#include <iomanip>
#include <tuple>
#include <set>
#include <cassert>
#include <numeric>

using namespace std;

#define FOR(i,n) for (int i = 0; i < n; ++i)
#define FORN(i, a, b) for (int i = a; i < b; ++i)
#define FORE(i, a, b) for (int i = a; i <= b; ++i)
#define DOWN(i,n) for (int i = n - 1; i >= 0; --i)
#define FORX(i,c) for(decltype(c.begin())i=c.begin();i!=c.end();++i)
#define SQR(x) ((x)*(x))
#define ALL(c) (c).begin(), (c).end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long LL;
typedef long double LDB;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, int> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;

const double EPS = 1e-11;
const int INF = ~(1 << 31);
const LL LINF = ~(1LL << 63);
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 2;

LL gcd(LL a, LL b) {
	return a == 0 ? b : gcd(b%a, a);
}

LL exp_pow(LL x, LL p, LL mod) {
	LL res = 1;
	while (p) {
		if (p & 1) {
			res = (res * x) % mod;
		}
		x = (x * x) % mod;
		p >>= 1;
	}
	return res;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(0);

#ifdef _KMK
	freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif // _KMK

	int n, k;
	cin >> n >> k;
	vector<vector<char>> a(n, vector<char>(n));
	FOR(i, n) {
		FOR(j, n) {
			cin >> a[i][j];
		}
	}

	vector<vector<pair<string, int>>> d(2, vector<pair<string, int>>(n));
	d[0][0] = { string(1, a[0][0]), 0 };
	if (k && a[0][0] != 'a') {
		d[0][0] = { "a", 1 };
	}

	int prev = 1;
	FOR(i, n) {

		int cur = prev ^ 1;
		FOR(j, n) {
			if (!i && !j) {
				continue;
			}
			pair<string, int> &pmin = d[prev][j];
			if (!i) {
				pmin = d[cur][j - 1];
			}
			else if (!j) {
				pmin = d[prev][j];
			}
			else {
				if (d[prev][j].first < d[cur][j - 1].first) {
					pmin = d[prev][j];
				}
				else if (d[prev][j].first > d[cur][j - 1].first) {
					pmin = d[cur][j - 1];
				}
				else {
					if (d[prev][j].second < d[cur][j - 1].second) {
						pmin = d[prev][j];
					}
					else {
						pmin = d[cur][j - 1];
					}
				}
			}

			d[cur][j].first.clear();
			d[cur][j].first.append(pmin.first);
			d[cur][j].second = pmin.second;
			if (a[i][j] != 'a' && d[cur][j].second < k) {
				d[cur][j].first += 'a';
				d[cur][j].second++;
			}
			else {
				d[cur][j].first += a[i][j];
			}
		}

		prev = cur;
	}

	cout << d[prev][n - 1].first;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <time.h>
#include <sstream>
#include <string>
#include <fstream>
#include <functional>
#include <list>
#include <cstring>
#include <iomanip>
#include <tuple>
#include <set>
#include <cassert>
#include <numeric>

using namespace std;

#define FOR(i,n) for (int i = 0; i < n; ++i)
#define FORN(i, a, b) for (int i = a; i < b; ++i)
#define FORE(i, a, b) for (int i = a; i <= b; ++i)
#define DOWN(i,n) for (int i = n - 1; i >= 0; --i)
#define FORX(i,c) for(decltype(c.begin())i=c.begin();i!=c.end();++i)
#define SQR(x) ((x)*(x))
#define ALL(c) (c).begin(), (c).end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long LL;
typedef long double LDB;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, int> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;

const double EPS = 1e-11;
const int INF = ~(1 << 31);
const LL LINF = ~(1LL << 63);
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 2;

LL gcd(LL a, LL b) {
	return a == 0 ? b : gcd(b%a, a);
}

LL exp_pow(LL x, LL p, LL mod) {
	LL res = 1;
	while (p) {
		if (p & 1) {
			res = (res * x) % mod;
		}
		x = (x * x) % mod;
		p >>= 1;
	}
	return res;
}

struct e {
	string first;
	int second;
};

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(0);

#ifdef _KMK
	freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif // _KMK

	int n, k;
	cin >> n >> k;
	vector<vector<char>> a(n, vector<char>(n));
	FOR(i, n) {
		FOR(j, n) {
			cin >> a[i][j];
		}
	}

	vector<vector<e>> d(2, vector<e>(n));
	d[0][0] = { "", 0 };
	if (k && a[0][0] != 'a') {
		d[0][0] = { "", 1};
	}

	int prev = 1;
	FOR(i, n) {

		int cur = prev ^ 1;
		FOR(j, n) {
			if (!i && !j) {
				continue;
			}
			e &pmin = d[cur][j];
			if (!i) {
				pmin = d[cur][j - 1];
			}
			else if (!j) {
				pmin = d[prev][j];
			}
			else {
				if (d[prev][j].second < d[cur][j - 1].second) {
					pmin = d[prev][j];
				}
				else if (d[prev][j].second > d[cur][j - 1].second) {
					pmin = d[cur][j - 1];
				}
				else {
					if (d[prev][j].first < d[cur][j - 1].first) {
						pmin = d[prev][j];
					}
					else {
						pmin = d[cur][j - 1];
					}
				}
			}

			if (a[i][j] != 'a' && pmin.second < k) {
				pmin.second++;
			}
			else if (pmin.first.length() || (pmin.second >= k && a[i][j] != 'a')) {
				pmin.first += a[i][j];
			}
		}

		prev = cur;
	}

	FOR(i, 2*n - 1 - d[prev][n - 1].first.length()) {
		cout << "a";
	}
	cout << d[prev][n - 1].first;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <time.h>
#include <sstream>
#include <string>
#include <fstream>
#include <functional>
#include <list>
#include <cstring>
#include <iomanip>
#include <tuple>
#include <set>
#include <cassert>
#include <numeric>

using namespace std;

#define FOR(i,n) for (int i = 0; i < n; ++i)
#define FORN(i, a, b) for (int i = a; i < b; ++i)
#define FORE(i, a, b) for (int i = a; i <= b; ++i)
#define DOWN(i,n) for (int i = n - 1; i >= 0; --i)
#define FORX(i,c) for(decltype(c.begin())i=c.begin();i!=c.end();++i)
#define SQR(x) ((x)*(x))
#define ALL(c) (c).begin(), (c).end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long LL;
typedef long double LDB;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, int> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;

const double EPS = 1e-11;
const int INF = ~(1 << 31);
const LL LINF = ~(1LL << 63);
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 2;

LL gcd(LL a, LL b) {
	return a == 0 ? b : gcd(b%a, a);
}

LL exp_pow(LL x, LL p, LL mod) {
	LL res = 1;
	while (p) {
		if (p & 1) {
			res = (res * x) % mod;
		}
		x = (x * x) % mod;
		p >>= 1;
	}
	return res;
}

struct e {
	string first;
	int second;
};

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(0);

#ifdef _KMK
	freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif // _KMK

	int n, k;
	cin >> n >> k;
	vector<vector<char>> a(n, vector<char>(n));
	FOR(i, n) {
		FOR(j, n) {
			cin >> a[i][j];
		}
	}

	vector<vector<e>> d(2, vector<e>(n));
	d[0][0] = { string(1, a[0][0]), 0 };
	if (k || a[0][0] == 'a') {
		d[0][0] = { "", a[0][0] != 'a' };
	}

	int prev = 1;
	FOR(i, n) {

		int cur = prev ^ 1;
		FOR(j, n) {
			if (!i && !j) {
				continue;
			}
			e &pmin = d[cur][j];
			if (!i) {
				pmin = d[cur][j - 1];
			}
			else if (!j) {
				pmin = d[prev][j];
			}
			else {
				if (d[prev][j].second < d[cur][j - 1].second) {
					pmin = d[prev][j];
				}
				else if (d[prev][j].second > d[cur][j - 1].second) {
					pmin = d[cur][j - 1];
				}
				else {
					if (d[prev][j].first.length() < d[cur][j - 1].first.length()) {
						pmin = d[prev][j];
					}
					else if (d[prev][j].first.length() > d[cur][j - 1].first.length()) {
						pmin = d[cur][j - 1];
					}
					else {
						if (d[prev][j].first < d[cur][j - 1].first) {
							pmin = d[prev][j];
						}
						else {
							pmin = d[cur][j - 1];
						}
					}
				}
			}

			if (a[i][j] != 'a' && pmin.second < k) {
				pmin.second++;
			}
			else if (pmin.first.length() || (pmin.second >= k && a[i][j] != 'a')) {
				pmin.first += a[i][j];
			}
		}

		prev = cur;
	}

	FOR(i, 2 * n - 1 - d[prev][n - 1].first.length()) {
		cout << "a";
	}
	cout << d[prev][n - 1].first;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <time.h>
#include <sstream>
#include <string>
#include <fstream>
#include <functional>
#include <list>
#include <cstring>
#include <iomanip>
#include <tuple>
#include <set>
#include <cassert>
#include <numeric>

using namespace std;

#define FOR(i,n) for (int i = 0; i < n; ++i)
#define FORN(i, a, b) for (int i = a; i < b; ++i)
#define FORE(i, a, b) for (int i = a; i <= b; ++i)
#define DOWN(i,n) for (int i = n - 1; i >= 0; --i)
#define FORX(i,c) for(decltype(c.begin())i=c.begin();i!=c.end();++i)
#define SQR(x) ((x)*(x))
#define ALL(c) (c).begin(), (c).end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long LL;
typedef long double LDB;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, int> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;

const double EPS = 1e-11;
const int INF = ~(1 << 31);
const LL LINF = ~(1LL << 63);
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 2;

LL gcd(LL a, LL b) {
	return a == 0 ? b : gcd(b%a, a);
}

LL exp_pow(LL x, LL p, LL mod) {
	LL res = 1;
	while (p) {
		if (p & 1) {
			res = (res * x) % mod;
		}
		x = (x * x) % mod;
		p >>= 1;
	}
	return res;
}

struct e {
	string first;
	int second;
};

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(0);

#ifdef _KMK
	freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif // _KMK

	int n, k;
	cin >> n >> k;
	vector<vector<char>> a(n, vector<char>(n));
	FOR(i, n) {
		FOR(j, n) {
			cin >> a[i][j];
		}
	}

	vector<vector<e>> d(2, vector<e>(n));
	d[0][0] = { string(1, a[0][0]), 0 };
	if (k || a[0][0] == 'a') {
		d[0][0] = { "", a[0][0] != 'a'};
	}

	int prev = 1;
	FOR(i, n) {

		int cur = prev ^ 1;
		FOR(j, n) {
			if (!i && !j) {
				continue;
			}
			e &pmin = d[cur][j];
			if (!i) {
				pmin = d[cur][j - 1];
			}
			else if (!j) {
				pmin = d[prev][j];
			}
			else {
				if (d[prev][j].second < d[cur][j - 1].second) {
					pmin = d[prev][j];
				}
				else if (d[prev][j].second > d[cur][j - 1].second) {
					pmin = d[cur][j - 1];
				}
				else {
					if (d[prev][j].first < d[cur][j - 1].first) {
						pmin = d[prev][j];
					}
					else {
						pmin = d[cur][j - 1];
					}
				}
			}

			if (a[i][j] != 'a' && pmin.second < k) {
				pmin.second++;
			}
			else if (pmin.second >= k) {
				pmin.first += a[i][j];
			}
		}

		prev = cur;
	}

	FOR(i, 2*n - 1 - d[prev][n - 1].first.length()) {
		cout << "a";
	}
	cout << d[prev][n - 1].first;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <time.h>
#include <sstream>
#include <string>
#include <fstream>
#include <functional>
#include <list>
#include <cstring>
#include <iomanip>
#include <tuple>
#include <set>
#include <cassert>
#include <numeric>

using namespace std;

#define FOR(i,n) for (int i = 0; i < n; ++i)
#define FORN(i, a, b) for (int i = a; i < b; ++i)
#define FORE(i, a, b) for (int i = a; i <= b; ++i)
#define DOWN(i,n) for (int i = n - 1; i >= 0; --i)
#define FORX(i,c) for(decltype(c.begin())i=c.begin();i!=c.end();++i)
#define SQR(x) ((x)*(x))
#define ALL(c) (c).begin(), (c).end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long LL;
typedef long double LDB;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, int> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;

const double EPS = 1e-11;
const int INF = ~(1 << 31);
const LL LINF = ~(1LL << 63);
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 2;

LL gcd(LL a, LL b) {
	return a == 0 ? b : gcd(b%a, a);
}

LL exp_pow(LL x, LL p, LL mod) {
	LL res = 1;
	while (p) {
		if (p & 1) {
			res = (res * x) % mod;
		}
		x = (x * x) % mod;
		p >>= 1;
	}
	return res;
}

struct e {
	string first;
	int second;
};

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(0);

#ifdef _KMK
	freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif // _KMK

	int n, k;
	cin >> n >> k;
	vector<vector<char>> a(n, vector<char>(n));
	FOR(i, n) {
		FOR(j, n) {
			cin >> a[i][j];
		}
	}

	vector<vector<e>> d(2, vector<e>(n));
	d[0][0] = { string(1, a[0][0]), 0 };
	if (k || a[0][0] == 'a') {
		d[0][0] = { "", a[0][0] != 'a'};
	}

	int prev = 1;
	FOR(i, n) {

		int cur = prev ^ 1;
		FOR(j, n) {
			if (!i && !j) {
				continue;
			}
			e &pmin = d[cur][j];
			if (!i) {
				pmin = d[cur][j - 1];
			}
			else if (!j) {
				pmin = d[prev][j];
			}
			else {
				if (d[prev][j].second < d[cur][j - 1].second) {
					pmin = d[prev][j];
				}
				else if (d[prev][j].second > d[cur][j - 1].second) {
					pmin = d[cur][j - 1];
				}
				else {
					if (d[prev][j].first < d[cur][j - 1].first) {
						pmin = d[prev][j];
					}
					else {
						pmin = d[cur][j - 1];
					}
				}
			}

			if (a[i][j] != 'a' && pmin.second < k) {
				pmin.second++;
			}
			else if (pmin.first.length() || (pmin.second >= k && a[i][j] != 'a')) {
				pmin.first += a[i][j];
			}
		}

		prev = cur;
	}

	FOR(i, 2*n - 1 - d[prev][n - 1].first.length()) {
		cout << "a";
	}
	cout << d[prev][n - 1].first;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <time.h>
#include <sstream>
#include <string>
#include <fstream>
#include <functional>
#include <list>
#include <cstring>
#include <iomanip>
#include <tuple>
#include <set>
#include <cassert>
#include <numeric>

using namespace std;

#define FOR(i,n) for (int i = 0; i < n; ++i)
#define FORN(i, a, b) for (int i = a; i < b; ++i)
#define FORE(i, a, b) for (int i = a; i <= b; ++i)
#define DOWN(i,n) for (int i = n - 1; i >= 0; --i)
#define FORX(i,c) for(decltype(c.begin())i=c.begin();i!=c.end();++i)
#define SQR(x) ((x)*(x))
#define ALL(c) (c).begin(), (c).end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long LL;
typedef long double LDB;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, int> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;

const double EPS = 1e-11;
const int INF = ~(1 << 31);
const LL LINF = ~(1LL << 63);
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 2;

LL gcd(LL a, LL b) {
	return a == 0 ? b : gcd(b%a, a);
}

LL exp_pow(LL x, LL p, LL mod) {
	LL res = 1;
	while (p) {
		if (p & 1) {
			res = (res * x) % mod;
		}
		x = (x * x) % mod;
		p >>= 1;
	}
	return res;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(0);

#ifdef _KMK
	freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif // _KMK

	int n, k;
	cin >> n >> k;
	vector<vector<char>> a(n, vector<char>(n));
	FOR(i, n) {
		FOR(j, n) {
			cin >> a[i][j];
		}
	}

	vector<vector<pair<string, int>>> d(n, vector<pair<string, int>>(n));
	d[0][0] = { string(1, a[0][0]), 0 };
	if (k && a[0][0] != 'a') {
		d[0][0] = { "a", 1 };
	}

	FOR(i, n) {
		FOR(j, n) {
			if (!i && !j) {
				continue;
			}
			pair<string, int> &pmin = d[i][j];
			if (!i) {
				pmin = d[i][j - 1];
			}
			else if (!j) {
				pmin = d[i - 1][j];
			}
			else {
				if (d[i - 1][j].first < d[i][j - 1].first) {
					pmin = d[i - 1][j];
				}
				else if (d[i - 1][j].first > d[i][j - 1].first) {
					pmin = d[i][j - 1];
				}
				else {
					if (d[i - 1][j].second < d[i][j - 1].second) {
						pmin = d[i - 1][j];
					}
					else {
						pmin = d[i][j - 1];
					}
				}
			}

			d[i][j] = pmin;
			if (a[i][j] != 'a' && d[i][j].second < k) {
				d[i][j].first += 'a';
				d[i][j].second++;
			}
			else {
				d[i][j].first += a[i][j];
			}
		}
	}

	cout << d[n - 1][n - 1].first;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <time.h>
#include <sstream>
#include <string>
#include <fstream>
#include <functional>
#include <list>
#include <cstring>
#include <iomanip>
#include <tuple>
#include <set>
#include <cassert>
#include <numeric>

using namespace std;

#define FOR(i,n) for (int i = 0; i < n; ++i)
#define FORN(i, a, b) for (int i = a; i < b; ++i)
#define FORE(i, a, b) for (int i = a; i <= b; ++i)
#define DOWN(i,n) for (int i = n - 1; i >= 0; --i)
#define FORX(i,c) for(decltype(c.begin())i=c.begin();i!=c.end();++i)
#define SQR(x) ((x)*(x))
#define ALL(c) (c).begin(), (c).end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long LL;
typedef long double LDB;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, int> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;

const double EPS = 1e-11;
const int INF = ~(1 << 31);
const LL LINF = ~(1LL << 63);
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 2;

LL gcd(LL a, LL b) {
	return a == 0 ? b : gcd(b%a, a);
}

LL exp_pow(LL x, LL p, LL mod) {
	LL res = 1;
	while (p) {
		if (p & 1) {
			res = (res * x) % mod;
		}
		x = (x * x) % mod;
		p >>= 1;
	}
	return res;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(0);

#ifdef _KMK
	freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif // _KMK

	int n, k;
	cin >> n >> k;
	vector<vector<char>> a(n, vector<char>(n));
	FOR(i, n) {
		FOR(j, n) {
			cin >> a[i][j];
		}
	}

	vector<vector<pair<string, int>>> d(2, vector<pair<string, int>>(n));
	d[0][0] = { string(1, a[0][0]), 0 };
	if (k && a[0][0] != 'a') {
		d[0][0] = { "a", 1 };
	}

	int prev = 1;
	FOR(i, n) {

		int cur = prev ^ 1;
		FOR(j, n) {
			if (!i && !j) {
				continue;
			}
			pair<string, int> pmin;
			if (!i) {
				pmin = d[cur][j - 1];
			}
			else if (!j) {
				pmin = d[prev][j];
			}
			else {
				if (d[prev][j].first < d[cur][j - 1].first) {
					pmin = d[prev][j];
				}
				else if (d[prev][j].first > d[cur][j - 1].first) {
					pmin = d[cur][j - 1];
				}
				else {
					if (d[prev][j].second < d[cur][j - 1].second) {
						pmin = d[prev][j];
					}
					else {
						pmin = d[cur][j - 1];
					}
				}
			}

			d[cur][j].first.clear();
			d[cur][j].first.append(pmin.first);
			d[cur][j].second = pmin.second;
			if (a[i][j] != 'a' && d[cur][j].second < k) {
				d[cur][j].first += 'a';
				d[cur][j].second++;
			}
			else {
				d[cur][j].first += a[i][j];
			}
		}

		prev = cur;
	}

	cout << d[prev][n - 1].first;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <time.h>
#include <sstream>
#include <string>
#include <fstream>
#include <functional>
#include <list>
#include <cstring>
#include <iomanip>
#include <tuple>
#include <set>
#include <cassert>
#include <numeric>

using namespace std;

#define FOR(i,n) for (int i = 0; i < n; ++i)
#define FORN(i, a, b) for (int i = a; i < b; ++i)
#define FORE(i, a, b) for (int i = a; i <= b; ++i)
#define DOWN(i,n) for (int i = n - 1; i >= 0; --i)
#define FORX(i,c) for(decltype(c.begin())i=c.begin();i!=c.end();++i)
#define SQR(x) ((x)*(x))
#define ALL(c) (c).begin(), (c).end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long LL;
typedef long double LDB;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, int> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;

const double EPS = 1e-11;
const int INF = ~(1 << 31);
const LL LINF = ~(1LL << 63);
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 2;
const int MAXCHAR = 125;

LL gcd(LL a, LL b) {
	return a == 0 ? b : gcd(b%a, a);
}

LL exp_pow(LL x, LL p, LL mod) {
	LL res = 1;
	while (p) {
		if (p & 1) {
			res = (res * x) % mod;
		}
		x = (x * x) % mod;
		p >>= 1;
	}
	return res;
}

struct e {
	string first;
	int second;
};

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(0);

#ifdef _KMK
	freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif // _KMK

	int n, k;
	cin >> n >> k;
	vector<vector<char>> a(n, vector<char>(n));
	FOR(i, n) {
		FOR(j, n) {
			cin >> a[i][j];
		}
	}

	vector<vector<char>> d(n, vector<char>(MAXCHAR));
	vector<vector<int>> ku(n, vector<int>(n, INF));

	d[0][0] = a[0][0];
	ku[0][0] = 0;
	if (k && a[0][0] != 'a') {
		d[0][0] = 'a';
		ku[0][0] = 1;
	}
	char bestPrevChar = d[0][0];
	vector<char> ans{};
	ans.push_back(bestPrevChar);

	FORN(sum, 1, 2 * n - 1) {
		int i = sum < n ? sum : n - 1;
		int j = sum < n ? 0 : sum - (n - 1);

		char bestCurChar = MAXCHAR;

		while (i >= 0 && j < n) {
			if (j && d[i][j - 1] == bestPrevChar) {
				ku[i][j] = min(ku[i][j], ku[i][j - 1]);
				d[i][j] = a[i][j];
			}
			if (i && d[i - 1][j] == bestPrevChar) {
				ku[i][j] = min(ku[i][j], ku[i - 1][j]);
				d[i][j] = a[i][j];
			}

			if (d[i][j]) {
				if (d[i][j] != 'a' && ku[i][j] < k) {
					d[i][j] = 'a';
					ku[i][j]++;
				}
				bestCurChar = min(bestCurChar, d[i][j]);
			}

			i--;
			j++;
		}

		ans.push_back(bestCurChar);
		bestPrevChar = bestCurChar;
	}

	for (auto c : ans) {
		cout << c;
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <time.h>
#include <sstream>
#include <string>
#include <fstream>
#include <functional>
#include <list>
#include <cstring>
#include <iomanip>
#include <tuple>
#include <set>
#include <cassert>
#include <numeric>

using namespace std;

#define FOR(i,n) for (int i = 0; i < n; ++i)
#define FORN(i, a, b) for (int i = a; i < b; ++i)
#define FORE(i, a, b) for (int i = a; i <= b; ++i)
#define DOWN(i,n) for (int i = n - 1; i >= 0; --i)
#define FORX(i,c) for(decltype(c.begin())i=c.begin();i!=c.end();++i)
#define SQR(x) ((x)*(x))
#define ALL(c) (c).begin(), (c).end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long LL;
typedef long double LDB;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, int> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;

const double EPS = 1e-11;
const int INF = ~(1 << 31);
const LL LINF = ~(1LL << 63);
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 2;
const int MAXCHAR = 125;

LL gcd(LL a, LL b) {
	return a == 0 ? b : gcd(b%a, a);
}

LL exp_pow(LL x, LL p, LL mod) {
	LL res = 1;
	while (p) {
		if (p & 1) {
			res = (res * x) % mod;
		}
		x = (x * x) % mod;
		p >>= 1;
	}
	return res;
}

struct e {
	string first;
	int second;
};

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(0);

#ifdef _KMK
	freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif // _KMK

	int n, k;
	cin >> n >> k;
	vector<vector<char>> a(n, vector<char>(n));
	FOR(i, n) {
		FOR(j, n) {
			cin >> a[i][j];
		}
	}

	//n = 2000, k = 2298;
	//vector<vector<char>> a(n, vector<char>(n, 'b'));

	vector<vector<char>> d(n, vector<char>(n, MAXCHAR));
	vector<vector<int>> ku(n, vector<int>(n, INF));

	d[0][0] = a[0][0];
	ku[0][0] = 0;
	if (k && a[0][0] != 'a') {
		d[0][0] = 'a';
		ku[0][0] = 1;
	}
	char bestPrevChar = d[0][0];
	vector<char> ans{};
	ans.push_back(bestPrevChar);

	FORN(sum, 1, 2 * n - 1) {
		int i = sum < n ? sum : n - 1;
		int j = sum < n ? 0 : sum - (n - 1);

		char bestCurChar = MAXCHAR;

		while (i >= 0 && j < n) {
			if (j && d[i][j - 1] == bestPrevChar) {
				ku[i][j] = min(ku[i][j], ku[i][j - 1]);
				d[i][j] = a[i][j];
			}
			if (i && d[i - 1][j] == bestPrevChar) {
				ku[i][j] = min(ku[i][j], ku[i - 1][j]);
				d[i][j] = a[i][j];
			}

			if (d[i][j]) {
				if (d[i][j] != 'a' && ku[i][j] < k) {
					d[i][j] = 'a';
					ku[i][j]++;
				}
				bestCurChar = min(bestCurChar, d[i][j]);
			}

			i--;
			j++;
		}

		ans.push_back(bestCurChar);
		bestPrevChar = bestCurChar;
	}

	for (auto c : ans) {
		cout << c;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
const double eps=1e-6;

time_t t1,t2;
int n,k;
char s[2005][2005];
string ans;
int tot;
void dfs(int x,int y,int ss,string a)
{
    tot++;
    if (tot>100000000&&rand()%3==0)
    {
        //cout<<ans<<endl;
        //cout<<difftime(t1,t2)<<endl;
        return;
    }
    if (ss<k&&s[x][y]!='a')
    {
        a.append(1,'a');
        ss++;
    }
    else
    {
        a.append(1,s[x][y]);
    }
    if (a>string(ans,0,x+y-1))
        return;
    if (x==n&&y==n)
    {
        if (a<ans)
            ans=a;
        return;
    }
    if (x<n&&y<n)
    {
        if (ss==k)
        {
            if (s[x+1][y]<s[x][y+1])
                dfs(x+1,y,ss,a);
            else if (s[x+1][y]>s[x][y+1])
                dfs(x,y+1,ss,a);
            else
            {
                dfs(x+1,y,ss,a);
                dfs(x,y+1,ss,a);
            }
        }
        else
        {
            dfs(x+1,y,ss,a);
            dfs(x,y+1,ss,a);
        }
    }
    else if (x<n)
        dfs(x+1,y,ss,a);
    else
        dfs(x,y+1,ss,a);
}
int main()
{
    scanf("%d%d",&n,&k);
    srand(time(NULL));
    tot=0;
    ans=string(2*n-1,'z');
    for (int i=1;i<=n;i++)
    {
        scanf("%s",s[i]+1);
    }
    dfs(1,1,0,"");
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
const double eps=1e-6;

time_t t1,t2;
int n,k;
char s[2005][2005];
string ans;
int tot;
void dfs(int x,int y,int ss,string a)
{
    tot++;
    if (tot>=10000000)
    {
        //cout<<ans<<endl;
        //cout<<difftime(t1,t2)<<endl;
        return;
    }
    if (ss<k&&s[x][y]!='a')
    {
        a.append(1,'a');
        ss++;
    }
    else
    {
        a.append(1,s[x][y]);
    }
    if (a>string(ans,0,x+y-1))
        return;
    if (x==n&&y==n)
    {
        if (a<ans)
            ans=a;
        return;
    }
    if (x<n&&y<n)
    {
        if (ss==k)
        {
            if (s[x+1][y]<s[x][y+1])
                dfs(x+1,y,ss,a);
            else if (s[x+1][y]>s[x][y+1])
                dfs(x,y+1,ss,a);
            else
            {
                dfs(x+1,y,ss,a);
                dfs(x,y+1,ss,a);
            }
        }
        else
        {
            dfs(x+1,y,ss,a);
            dfs(x,y+1,ss,a);
        }
    }
    else if (x<n)
        dfs(x+1,y,ss,a);
    else
        dfs(x,y+1,ss,a);
}
int main()
{
    scanf("%d%d",&n,&k);
    srand(time(NULL));
    tot=0;
    ans=string(2*n-1,'z');
    for (int i=1;i<=n;i++)
    {
        scanf("%s",s[i]+1);
    }
    dfs(1,1,0,"");
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
const double eps=1e-6;

int n,k;
char s[2005][2005];
string ans;
void dfs(int x,int y,int ss,string a)
{
    if (ss<k&&s[x][y]!='a')
    {
        a.append(1,'a');
        ss++;
    }
    else
    {
        a.append(1,s[x][y]);
    }
    if (a>string(ans,0,x+y-1))
        return;
    if (x==n&&y==n)
    {
        if (a<ans)
            ans=a;
        return;
    }
    if (x<n&&y<n)
    {
        if (ss==k)
        {
            if (s[x+1][y]<s[x][y+1])
                dfs(x+1,y,ss,a);
            else if (s[x+1][y]>s[x][y+1])
                dfs(x,y+1,ss,a);
            else
            {
                dfs(x+1,y,ss,a);
                dfs(x,y+1,ss,a);
            }
        }
        else
        {
            dfs(x+1,y,ss,a);
            dfs(x,y+1,ss,a);
        }
    }
    else if (x<n)
        dfs(x+1,y,ss,a);
    else
        dfs(x,y+1,ss,a);
}
int main()
{
    scanf("%d%d",&n,&k);
    ans=string(2*n-1,'z');
    for (int i=1;i<=n;i++)
    {
        scanf("%s",s[i]+1);
    }
    dfs(1,1,0,"");
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
const double eps=1e-6;

time_t t1,t2;
int n,k;
char s[2005][2005];
string ans;
int tot;
void dfs(int x,int y,int ss,string a)
{
    tot++;
    if (tot>10000000&&rand()%3!=0)
    {
        //cout<<ans<<endl;
        //cout<<difftime(t1,t2)<<endl;
        return;
    }
    if (ss<k&&s[x][y]!='a')
    {
        a.append(1,'a');
        ss++;
    }
    else
    {
        a.append(1,s[x][y]);
    }
    if (a>string(ans,0,x+y-1))
        return;
    if (x==n&&y==n)
    {
        if (a<ans)
            ans=a;
        return;
    }
    if (x<n&&y<n)
    {
        if (ss==k)
        {
            if (s[x+1][y]<s[x][y+1])
                dfs(x+1,y,ss,a);
            else if (s[x+1][y]>s[x][y+1])
                dfs(x,y+1,ss,a);
            else
            {
                dfs(x+1,y,ss,a);
                dfs(x,y+1,ss,a);
            }
        }
        else
        {
            dfs(x+1,y,ss,a);
            dfs(x,y+1,ss,a);
        }
    }
    else if (x<n)
        dfs(x+1,y,ss,a);
    else
        dfs(x,y+1,ss,a);
}
int main()
{
    scanf("%d%d",&n,&k);
    srand(time(NULL));
    tot=0;
    ans=string(2*n-1,'z');
    for (int i=1;i<=n;i++)
    {
        scanf("%s",s[i]+1);
    }
    dfs(1,1,0,"");
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long
#define LL long long
#define rg register
#define pt(x) printf("%d ", x);
#define Fin(x) {freopen(#x".in","r",stdin);}
#define Fout(x) {freopen(#x".out","w",stdout);}
using namespace std;
const int MAXN = 2001, INF = 1e9 + 10, mod = 1e9 + 7, B = 1;
const double eps = 1e-9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N, K, vis[MAXN][MAXN], f[MAXN][MAXN];
char s[MAXN][MAXN];
int main() {
    N = read(); K = read();
    for(int i = 1; i <= N; i++) scanf("%s", s[i] + 1);
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            f[i][j] = max(f[i - 1][j], f[i][j - 1]);
            if(s[i][j] == 'a') f[i][j]++;
            if(i + j - 1 - f[i][j] <= K) s[i][j] = 'a';
        }
    }
    putchar(s[1][1]); vis[1][1] = 1;
    for(int i = 3; i <= N << 1; i++) {//all step
        char now = 'z' + 1;
        for(int j = 1; j < i; j++) { // num of down
            if(j > N || (i - j > N)) continue;
            if(!vis[j - 1][i - j] && !vis[j][i - j - 1]) continue;
            now = min(now, s[j][i - j]);
        }
        putchar(now);
        for(int j = 1; j < i; j++) { // num of down
            if(j > N || (i - j > N)) continue;
            if(!vis[j - 1][i - j] && !vis[j][i - j - 1]) continue;
            if(s[j][i - j] == now) vis[j][i - j] = 1;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
const double eps=1e-6;

time_t t1,t2;
int n,k;
char s[2005][2005];
string ans;
int tot;
void dfs(int x,int y,int ss,string a)
{
    tot++;
    if (tot>10000000&&rand()%3==0)
    {
        //cout<<ans<<endl;
        //cout<<difftime(t1,t2)<<endl;
        return;
    }
    if (ss<k&&s[x][y]!='a')
    {
        a.append(1,'a');
        ss++;
    }
    else
    {
        a.append(1,s[x][y]);
    }
    if (a>string(ans,0,x+y-1))
        return;
    if (x==n&&y==n)
    {
        if (a<ans)
            ans=a;
        return;
    }
    if (x<n&&y<n)
    {
        if (ss==k)
        {
            if (s[x+1][y]<s[x][y+1])
                dfs(x+1,y,ss,a);
            else if (s[x+1][y]>s[x][y+1])
                dfs(x,y+1,ss,a);
            else
            {
                dfs(x+1,y,ss,a);
                dfs(x,y+1,ss,a);
            }
        }
        else
        {
            dfs(x+1,y,ss,a);
            dfs(x,y+1,ss,a);
        }
    }
    else if (x<n)
        dfs(x+1,y,ss,a);
    else
        dfs(x,y+1,ss,a);
}
int main()
{
    scanf("%d%d",&n,&k);
    srand(time(NULL));
    tot=0;
    ans=string(2*n-1,'z');
    for (int i=1;i<=n;i++)
    {
        scanf("%s",s[i]+1);
    }
    dfs(1,1,0,"");
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
const double eps=1e-6;

int n,k;
char s[2005][2005];
string ans;
void dfs(int x,int y,int ss,string a)
{
    if (ss<k&&s[x][y]!='a')
    {
        a.append(1,'a');
        ss++;
    }
    else
    {
        a.append(1,s[x][y]);
    }
    if (x==n&&y==n)
    {
        if (a<ans)
            ans=a;
        return;
    }
    if (x<n&&y<n)
    {
        if (ss==k)
        {
            if (s[x+1][y]<s[x][y+1])
                dfs(x+1,y,ss,a);
            else if (s[x+1][y]>s[x][y+1])
                dfs(x,y+1,ss,a);
            else
            {
                dfs(x+1,y,ss,a);
                dfs(x,y+1,ss,a);
            }
        }
        else
        {
            dfs(x+1,y,ss,a);
            dfs(x,y+1,ss,a);
        }
    }
    else if (x<n)
        dfs(x+1,y,ss,a);
    else
        dfs(x,y+1,ss,a);
}
int main()
{
    scanf("%d%d",&n,&k);
    ans="";
    ans.append(2*n-1,'z');
    for (int i=1;i<=n;i++)
    {
        scanf("%s",s[i]+1);
    }
    dfs(1,1,0,"");
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
const double eps=1e-6;

time_t t1,t2;
int n,k;
char s[2005][2005];
string ans;
int tot;
void dfs(int x,int y,int ss,string a)
{
    tot++;
    if (tot>1000000)
    {
        //cout<<ans<<endl;
        //cout<<difftime(t1,t2)<<endl;
        return;
    }
    if (ss<k&&s[x][y]!='a')
    {
        a.append(1,'a');
        ss++;
    }
    else
    {
        a.append(1,s[x][y]);
    }
    if (a>string(ans,0,x+y-1))
        return;
    if (x==n&&y==n)
    {
        if (a<ans)
            ans=a;
        return;
    }
    if (x<n&&y<n)
    {
        if (ss==k)
        {
            if (s[x+1][y]<s[x][y+1])
                dfs(x+1,y,ss,a);
            else if (s[x+1][y]>s[x][y+1])
                dfs(x,y+1,ss,a);
            else
            {
                dfs(x+1,y,ss,a);
                dfs(x,y+1,ss,a);
            }
        }
        else
        {
            dfs(x+1,y,ss,a);
            dfs(x,y+1,ss,a);
        }
    }
    else if (x<n)
        dfs(x+1,y,ss,a);
    else
        dfs(x,y+1,ss,a);
}
int main()
{
    scanf("%d%d",&n,&k);
    srand(time(NULL));
    tot=0;
    ans=string(2*n-1,'z');
    for (int i=1;i<=n;i++)
    {
        scanf("%s",s[i]+1);
    }
    dfs(1,1,0,"");
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
const double eps=1e-6;

time_t t1,t2;
int n,k;
char s[2005][2005];
string ans;
void dfs(int x,int y,int ss,string a)
{
    t2 = time(NULL);
    if ((difftime(t1,t2))*1.0>1.3)
    {
        //cout<<ans<<endl;
        return;
    }
    if (ss<k&&s[x][y]!='a')
    {
        a.append(1,'a');
        ss++;
    }
    else
    {
        a.append(1,s[x][y]);
    }
    if (a>string(ans,0,x+y-1))
        return;
    if (x==n&&y==n)
    {
        if (a<ans)
            ans=a;
        return;
    }
    if (x<n&&y<n)
    {
        if (ss==k)
        {
            if (s[x+1][y]<s[x][y+1])
                dfs(x+1,y,ss,a);
            else if (s[x+1][y]>s[x][y+1])
                dfs(x,y+1,ss,a);
            else
            {
                dfs(x+1,y,ss,a);
                dfs(x,y+1,ss,a);
            }
        }
        else
        {
            dfs(x+1,y,ss,a);
            dfs(x,y+1,ss,a);
        }
    }
    else if (x<n)
        dfs(x+1,y,ss,a);
    else
        dfs(x,y+1,ss,a);
}
int main()
{
    scanf("%d%d",&n,&k);
    t1 = time(NULL);
    ans=string(2*n-1,'z');
    for (int i=1;i<=n;i++)
    {
        scanf("%s",s[i]+1);
    }
    dfs(1,1,0,"");
    cout<<ans<<endl;
    return 0;
}


using System;

namespace vanyaandfence
{
    public class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int h =int.Parse(Console.ReadLine());
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i]=int.Parse(Console.ReadLine());
            }
            int MinWidth=0;
            for (int i = 0; i < n; i++)
            {
                if (a[i]>h)
                    MinWidth+=2;
                else
                    MinWidth++;
            }
            Console.WriteLine(MinWidth);
        }
    }
}


using System;

namespace vanay_fence
{
    class Program
    {
        static void Main(string[] args)
        {
           var firstline = Console.ReadLine().Split(' ');
           int fenceheight = int.Parse(firstline[1]);
           var personsheight= Console.ReadLine().Split(' ');
           int roadWidth = 0;
           for (int i = 0; i < personsheight.Length; i++)
           {
               if (int.Parse(personsheight[i]) > fenceheight)
                    roadWidth+=2;
                else
                    roadWidth++;
           }
           System.Console.WriteLine(roadWidth);
        }
    }
}


using System;

namespace vanyaandfence
{
    public class Program
    {
        static void Main(string[] args)
        {
            string[] tokens =Console.ReadLine().Split();
            int n = int.Parse(tokens[0]);
            int h = int.Parse(tokens[1]);
            int[] a = new int[n];
            string[] nums = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                a[i]=int.Parse(nums[i]);
            }

            int MinWidth = 0;
            for (int i = 0; i < n; i++)
            {
                if (a[i] > h)
                    MinWidth += 2;
                else
                    MinWidth++;
            }
            Console.WriteLine(MinWidth);
        }
    }
}


using System;

namespace Vanya_and_Fence
{
    class Program
    {
        static void Main(string[] args)
        {
            var firstLine = Console.ReadLine().Split(' ');
            var friendsHeights = Console.ReadLine().Split(' ');
            int roadWidth = 0, friendsCount = int.Parse(firstLine[0]), fenceHeight = int.Parse(firstLine[1]);
            for (int i = 0; i < friendsCount; i++)
            {
                int friend = int.Parse(friendsHeights[i]);
                if (friend > fenceHeight)
                {
                    roadWidth += 2;
                    continue;
                }
                else
                    roadWidth++;
            }
            System.Console.WriteLine(roadWidth);
        }
    }
}


using System;

namespace VanyaandFence
{
    class Program
    {
        static void Main(string[] args)
        {
            var input  = Console.ReadLine().Split(' ');
            var roadwith = 0;
            var height = int.Parse(input[1]);
            var firends   = Console.ReadLine().Split(' ');
            for (int i = 0; i < firends.Length; i++)
            {
                if(int.Parse(firends[i])<= height)
                    roadwith++;
                else
                    roadwith+=2;
            }
            System.Console.WriteLine(roadwith);
        }
    }
}


            int n = int.Parse(Console.ReadLine());
            int h =int.Parse(Console.ReadLine());
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i]=int.Parse(Console.ReadLine());
            }
            int MinWidth=0;
            for (int i = 0; i < n; i++)
            {
                if (a[i]>h)
                    MinWidth+=2;
                else
                    MinWidth++;
            }
            Console.WriteLine(MinWidth);


using System;

namespace VanyaandFence
{
    class Program
    {
        static void Main(string[] args)
        {
            var input  = Console.ReadLine().Split(" ");
            var roadwith = 0;
            var height = int.Parse(input[1]);
            var firends   = Console.ReadLine().Split(" ");
            for (int i = 0; i < firends.Length; i++)
            {
                if(int.Parse(firends[i])<= height)
                    roadwith++;
                else
                    roadwith+=2;
            }
            System.Console.WriteLine(roadwith);
        }
    }
}


using System;
using System.Linq;

class MainClass {
  public static void Main (string[] args) {
    int[] inputs = Console.ReadLine().Split(' ').Select<string,int>(int.Parse).ToArray();
    int n = inputs[0] , h = inputs[1];
    int[] p = Console.ReadLine().Split(' ').Select<string,int>(int.Parse).ToArray();
    int r  = 0;
    for(int i = 0 ; i < n ; i++){
      if(p[i] <= h){
        r += 1;
      }else{
        r += 2;
      }
    }
    Console.WriteLine(r);
  }
}


namespace VanyaAndFence
{
    class Program
    {
        static public int Main(int n = 0, int h = 0, params int[] personsHeight )
        {
            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;

        }

    }
}


using System;

namespace VanyaAndFence
{
    class Program
    {
        static void Main(string[] args)
        {

            int widthSumOne = VanyaAndFence(3, 7, 4, 5, 14);
            Console.WriteLine(widthSumOne);

        }
        static public int VanyaAndFence(int n, int h, params int[] personsHeight)
        {

            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;
        }
    }
}


using System;

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = Convert.ToInt32(input[0]);
        int h = Convert.ToInt32(input[1]);
        int[] personsHeight = new int[n];

        input = Console.ReadLine().Split(' ');

        for (int i = 0; i < personsHeight.Length; i++)
        {
            personsHeight[i] = Convert.ToInt32(input[i]);
        }

        Console.WriteLine(VanyaAndFence(n, h, personsHeight));

    }
     public static int VanyaAndFence(int n, int h, int[] personsHeight)
    {

        int widthSumResult = 0;
        for (int i = 0; i < n; i++)
        {
            if (personsHeight[i] > h)
            {
                widthSumResult += 2;
            }
            else
            {
                widthSumResult++;
            }
        }

        return widthSumResult;
    }
}


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29409.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VanyaAndFence", "VanyaAndFence\VanyaAndFence.csproj", "{58F907CB-E151-4341-9BF0-8735B5FC3177}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{58F907CB-E151-4341-9BF0-8735B5FC3177}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{58F907CB-E151-4341-9BF0-8735B5FC3177}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{58F907CB-E151-4341-9BF0-8735B5FC3177}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{58F907CB-E151-4341-9BF0-8735B5FC3177}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(ExtensibilityGlobals) = postSolution
		SolutionGuid = {9C1D72F2-71B8-4EDC-9DA6-EAD4499678BD}
	EndGlobalSection
EndGlobal


using System;

namespace VanyaAndFence
{
    class Program
    {
        static void Main()
        {
           int minimumWidth = VanyaAndFence();
            Console.WriteLine(minimumWidth);
        }

        static public int VanyaAndFence(int n = 0, int h = 0, params int[] personsHeight)
        {

            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;
        }
    }
}


using System;

namespace VanyaAndFence
{
    class Program
    {
        static void Main(string[] args)
        {

            int widthSumOne = VanyaAndFence(3, 7, 4, 5, 14);
            Console.WriteLine(widthSumOne);
             int widthSumTow = VanyaAndFence(6, 1, 1, 1, 1, 1, 1, 1);
            Console.WriteLine(widthSumTow);
             int widthSumThree = VanyaAndFence(6, 5, 7, 6, 8, 9, 10, 5);
            Console.WriteLine(widthSumThree);

        }
        static public int VanyaAndFence(int n, int h, params int[] personsHeight)
        {

            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;
        }
    }
}


 class Program
    {
        static void Main(string[] args)
        {

            int widthSum = VanyaAndFence(6,1, 1, 1, 1, 1, 1, 1);
            Console.WriteLine(widthSum);
            Console.ReadLine();

        }
        static public int VanyaAndFence(int n, int h, params int[] personsHeight)
        {

            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;
        }
    }


 using System;

 class Program
    {
        static void Main(string[] args)
        {

            int widthSum = VanyaAndFence(6,1, 1, 1, 1, 1, 1, 1);
            Console.WriteLine(widthSum);
            Console.ReadLine();

        }
        static public int VanyaAndFence(int n, int h, params int[] personsHeight)
        {

            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;
        }
    }


using System;

namespace VanyaAndFence
{
    class Program
    {
        static void Main()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int h = Convert.ToInt32(Console.ReadLine());
            int[] personsHeight = new int[n];
            for (int i = 0; i < personsHeight.Length; i++)
            {
                personsHeight[i] = Convert.ToInt32(Console.ReadLine());
            }

            VanyaAndFence(n,h, personsHeight);

        }

        static public int VanyaAndFence(int n , int h , int[] personsHeight)
        {

            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;
        }
    }
}


using System;

namespace VanyaAndFence
{
    class Program
    {
        static void Main(string[] args)
        {

            int widthSum = VanyaAndFence(6,1, 1, 1, 1, 1, 1, 1);
            Console.WriteLine(widthSum);
            Console.ReadLine();

        }
        static public int VanyaAndFence(int n, int h, params int[] personsHeight)
        {

            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;
        }
    }
}


using System;

namespace VanyaAndFence
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter the number of the friends:");
            int n = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Please enter the height of the fence:");
            int h = Convert.ToInt32(Console.ReadLine());
            int[] personsHeight = new int[n];
            for (int i = 0; i < personsHeight.Length; i++)
            {
                Console.WriteLine(string.Format("Please enter the height of persone [{0}]:", i+1));
                personsHeight[i] = Convert.ToInt32(Console.ReadLine());
            }

            Console.WriteLine(VanyaAndFence(n, h, personsHeight));

        }

        static public int VanyaAndFence(int n, int h, params int[] personsHeight)
        {

            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;
        }
    }
}


namespace VanyaAndFence
{
    class Program
    {
        static void Main()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int h = Convert.ToInt32(Console.ReadLine());
            VanyaAndFence(n,h);

        }

        static public int VanyaAndFence(int n , int h , params int[] personsHeight)
        {

            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;
        }
    }
}


using System;

namespace VanyaAndFence
{
    class Program
    {
        static void Main(string[] args)
        {

            int widthSum = VanyaAndFence(3,7,4,5,14);
            Console.WriteLine(widthSum);
            Console.ReadLine();

        }
        static public int VanyaAndFence(int n, int h, params int[] personsHeight)
        {

            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;
        }
    }
}


using System;

namespace VanyaAndFence
{
    class Program
    {
        static void Main()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int h = Convert.ToInt32(Console.ReadLine());
            int[] personsHeight = new int[n];
            VanyaAndFence(n,h, personsHeight);

        }

        static public int VanyaAndFence(int n , int h , params int[] personsHeight)
        {

            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;
        }
    }
}


using System;

namespace VanyaAndFence
{
    class Program
    {
        static void Main()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int h = Convert.ToInt32(Console.ReadLine());
            VanyaAndFence(n,h);

        }

        static public int VanyaAndFence(int n , int h , params int[] personsHeight)
        {

            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;
        }
    }
}


namespace VanyaAndFence
{
    class Program
    {
        static void Main()
        {
            VanyaAndFence();

        }

        static public int VanyaAndFence(int n = 0, int h = 0, params int[] personsHeight)
        {

            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;
        }
    }


using System;

namespace VanyaAndFence
{
    class Program
    {
        static void Main(string[] args)
        {

            int widthSum = VanyaAndFence(3, 7, 4, 5, 14);
            Console.WriteLine(widthSum);
             int widthSum = VanyaAndFence(6, 1, 1, 1, 1, 1, 1, 1);
            Console.WriteLine(widthSum);
             int widthSum = VanyaAndFence(6, 5, 7, 6, 8, 9, 10, 5);
            Console.WriteLine(widthSum);
            Console.ReadLine();

        }
        static public int VanyaAndFence(int n, int h, params int[] personsHeight)
        {

            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;
        }
    }
}


using System;

namespace VanyaAndFence
{
    class Program
    {
        static void Main(string[] args)
        {

            int widthSum = VanyaAndFence(3,7, 4,5,14);
            Console.WriteLine(widthSum);
            Console.ReadLine();

        }
        static public int VanyaAndFence(int n, int h, params int[] personsHeight)
        {

            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;
        }
    }
}


namespace VanyaAndFence
{
    class Program
    {
        static void Main()
        {
            VanyaAndFence();

        }

        static public int VanyaAndFence(int n = 0, int h = 0, params int[] personsHeight)
        {

            int widthSumResult = 0;
            for (int i = 0; i < n; i++)
            {
                if (personsHeight[i] > h)
                {
                    widthSumResult += 2;
                }
                else
                {
                    widthSumResult++;
                }
            }

            return widthSumResult;
        }
    }
}


using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var line1 = Console.ReadLine();
            var parts = line1.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
            var numbers = int.Parse(parts[0]);
            var height =  int.Parse(parts[1]);
            var line2 = Console.ReadLine();
            parts = line2.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);

            int sum = 0;

            foreach (var part in parts)
            {
                var number = int.Parse(part);
                sum += number <= height ? 1 : 2;
            }

            Console.WriteLine(sum);
        }
    }
}


using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var line1 = Console.ReadLine();
            var parts = line1.Split(" ", StringSplitOptions.RemoveEmptyEntries);
            var numbers = int.Parse(parts[0]);
            var height =  int.Parse(parts[1]);
            var line2 = Console.ReadLine();
            parts = line2.Split(" ", StringSplitOptions.RemoveEmptyEntries);

            int sum = 0;

            foreach (var part in parts)
            {
                var number = int.Parse(part);
                sum += number <= height ? 1 : 2;
            }

            Console.WriteLine(sum);
        }
    }
}


using System;
using System.Linq;
public class Program
{

    public static void Main()
    {
		string[] first = Console.ReadLine().Split();
		string[] second = Console.ReadLine().Split();
		int n = int.Parse(first[0]), h = int.Parse(first[1]);
		int count = 0;
		for(int i=0; i<n; i++)
		{
			if(h>int.Parse(second[i]))
			{
				count+=2;
			}
			else
			{
				count++;
			}
		}
		Console.WriteLine(count);
    }
}


using System;
using System.Linq;
public class Program
{

    public static void Main()
    {
		string[] first = Console.ReadLine().Split();
		string[] second = Console.ReadLine().Split();
		int n = int.Parse(first[0]), h = int.Parse(first[1]);
		int count = 0;
		for(int i=0; i<n; i++)
		{
			if(h<int.Parse(second[i]))
			{
				count+=2;
			}
			else
			{
				count++;
			}
		}
		Console.WriteLine(count);
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Solution
{
    class Program
    {
        static void Main(string[] args)
        {
            var inp = Console.ReadLine().Split();
            var friends = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var fenceH = int.Parse(inp[1]);
            var result = 0;
            foreach (var fr in friends)
                result += (fr <= fenceH) ? 1 : 2;
            Console.WriteLine(result);
        }
    }
}


using System;

namespace Vanya_and_Fence
{
    class Program
    {
        static void Main(string[] args)
        {
            string l1 = Console.ReadLine();
            string[] s1=l1.Split(' ');
            int n = int.Parse(s1[0]);
            int h = int.Parse(s1[1]);
            int res = 0;
            string l2 = Console.ReadLine();
            string[] s2 = l2.Split(' ');
            for (int i = 0; i< n; i++)
            {
                res++;
                if (int.Parse(s2[i]) > h)
                    res++;

            }
            Console.WriteLine(res);

        }
    }
}


using System;
namespace Vanya_and_Fence
{
    class Program
    {
        static void Main(string[] args)
        {
            string l1 = Console.ReadLine();
            string[] s1=l1.Split(' ');
            int n = int.Parse(s1[0]);
            int h = int.Parse(s1[1]);
            int res = 0;
            string l2 = Console.ReadLine();
            string[] s2 = l1.Split(' ');
            for (int i = 0; i < n; i++)
            {
                if (int.Parse(s2[i]) <= h)
                    res++;
                else res += 2;

            }
            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Vanya_and_Fence
{
    class Program
    {
        static void Main(string[] args)
        {
            string l1 = Console.ReadLine();
            string[] s1=l1.Split(' ');
            int n = int.Parse(s1[0]);
            int h = int.Parse(s1[1]);
            string l2 = Console.ReadLine();
            string[] s2 = l2.Split(' ');
            int[] nl = new int[n];
            int i = 0;
            foreach (string s in s2)
            {
                nl[i] = int.Parse(s);
                i++;
            }
            int res=0;
            foreach (int num in nl)
            {
                if (num <= h)
                {
                    res++;
                }
                else res += 2;
            }
            Console.WriteLine(res);
        }
    }
}


using System;

namespace Vanya_and_Fence
{
    class Program
    {
        static void Main(string[] args)
        {
            string l1 = Console.ReadLine();
            string[] s1=l1.Split(' ');
            int n = int.Parse(s1[0]);
            int h = int.Parse(s1[1]);
            int res = 0;
            string l2 = Console.ReadLine();
            string[] s2 = l2.Split(' ');
            for (int i = 0; i< n; i++)
            {
                if (int.Parse(s2[i]) <= h)
                    res++;
                else res += 2;

            }
            Console.WriteLine(res);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Vanya_and_Fence
{
    class Program
    {
        static void Main(string[] args)
        {
            string l1 = Console.ReadLine();
            string[] s1=l1.Split(' ');
            int n = int.Parse(s1[0]);
            int h = int.Parse(s1[1]);
            int res = 0;
            for (int i = 0; i < n; i++)
            {
                if (int.Parse(Console.ReadLine()) <= h)
                    res++;
                else res += 2;

            }
            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;

namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
          //  var t = int.Parse(Console.ReadLine());

           // while (t-- > 0)
            //{
                var nh = Console.ReadLine().Split(' ');
                var n = long.Parse(nh[0]);
                var h = long.Parse(nh[1]);

                var array = Console.ReadLine().Split(' ');

                foreach (var a in array)
                {
                    var q = int.Parse(a);
                    if (q > h) { n++; }
                }

                Console.WriteLine(n);
            //}

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CodeForces
{
    public class Test
    {
        public static void Main()
        {
            int[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), temp => Convert.ToInt32(temp));
            int n = arr[0];
            int h = arr[1];
            int[] heights = Array.ConvertAll(Console.ReadLine().Split(' '), temp => Convert.ToInt32(temp));
            int c = 0;
            for (int i = 0; i < n; i++)
            {
                if (heights[i] > h)
                    c++;
            }
            Console.WriteLine(c * 2 + (n - c));
        }

    }
}


using System;

public class Program
{
	public static void Main()
	{
		string input = Console.ReadLine();
		string heights = Console.ReadLine();
		string [] _NHvalues=input.Split(' ');
		string [] _heightsValues=heights.Split(' ');
         int count=0;
		for(int i=0;i< Int32.Parse(_NHvalues[0]);i++){
			if(Int32.Parse(_heightsValues[i])>Int32.Parse(_NHvalues[1])){
				count=count+2;
			}
			else{
				count++;
			}
		}
		Console.WriteLine(count);
	}
}


using System;
using System.Collections;
using System.Collections.Generic;

class Solution
{
    static void Main(string[] args)
    {
        string[] ab = Console.ReadLine().Split(' ');
        int nooffriends = Convert.ToInt32(ab[0]), height = Convert.ToInt32(ab[1]), width = 0;
        int[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), item => Convert.ToInt32(item));
        Array.Sort(arr);
        for(int i=0;i<arr.Length;i++)
        {
            if (arr[i] > height) width += 2;
            else width += 1;
        }
        Console.Write(width);
    }
}


using System;

namespace _677A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int h = int.Parse(input[1]);
            int result = 0;
            input = Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
            {
                int cur = int.Parse(input[i]);
                if (cur > h) result++;
                result++;
            }
            Console.WriteLine(result);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Vanya_and_Fence_code_force
{
    class Program
    {
        static void Main(string[] args)
        {
            int n=0, h=0,outp=2;
            string line1 = Console.ReadLine();
            for(int i=0;i<line1.Length;i++)
            {
                if(line1[i]==' ')
                {
                     n = Convert.ToInt32(line1.Substring(0, i));
                     h = Convert.ToInt32(line1.Substring(i));
                    break;
                }
            }
            int[] arr = Console.ReadLine().Split(' ').Take(n).Select(int.Parse).ToArray();
           for(int i = 0; i < arr.Length; i++)
            {
                if (arr[i] > h)
                {
                    outp+=2;
                }
                else
                {
                    outp++;
                }
            }
            Console.WriteLine(outp);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Vanya_and_Fence_code_force
{
    class Program
    {
        static void Main(string[] args)
        {
            int n=0, h=0,outp=0;
            string line1 = Console.ReadLine();
            for(int i=0;i<line1.Length;i++)
            {
                if(line1[i]==' ')
                {
                     n = Convert.ToInt32(line1.Substring(0, i));
                     h = Convert.ToInt32(line1.Substring(i));
                    break;
                }
            }
            int[] arr = Console.ReadLine().Split(' ').Take(n).Select(int.Parse).ToArray();

            for (int i = 0; i < n; i++)
            {
                if (arr[i] > h)
                {
                    outp+=2;
                }
                else
                {
                    outp++;
                }
            }
            Console.WriteLine(outp);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SheetOne
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tokens = Console.ReadLine().Split();

            int numberOfFriends = int.Parse(tokens[0]);
          int  heightOfHens  = int.Parse(tokens[1]);
          int result = 0;
            int[] heightsOfFriends= new int[numberOfFriends];
            tokens = Console.ReadLine().Split();

          for (int i = 0; i < numberOfFriends; i++)
          {
              heightsOfFriends[i] = int.Parse(tokens[i]);
          }
          for (int i = 0; i < numberOfFriends; i++)
          {
              if (heightOfHens>=heightsOfFriends[i])
              {
                  result += 1;
              }
              else
              {
                  result += 2;
              }
          }
          Console.WriteLine(result);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tests
{
    class Program
    {
        static void Main(string[] args)
        {
            int lol, inp,res=0;
            string guba,sota;
            guba = Console.ReadLine();
            sota = Console.ReadLine();

            lol = int.Parse(guba.Split(' ')[0]);
            inp = int.Parse(guba.Split(' ')[1]);

            string[] s = sota.Split(' ');
            foreach (string o in s)
            {

                if (int.Parse(o) > inp)
                {
                    res += 2;
                }
                else
                {
                    res += 1;
                }

            }
            Console.WriteLine(res.ToString());
           // Console.ReadKey();

        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tests
{
    class Program
    {
        static void Main(string[] args)
        {
            int lol, inp,res=0;
            string guba,sota;
            guba = Console.ReadLine();
            sota = Console.ReadLine();

            lol = int.Parse(guba.Split(' ')[0]);
            inp = int.Parse(guba.Split(' ')[1]);

            for (int i = 0; i < lol; i+=2)
            {
                if (sota[i] > inp)
                {
                    res += 2;
                }
                else
                {
                    res += 1;
                }

            }
            Console.WriteLine(res.ToString());

        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace testss
{
    class Program
    {
        static int n = 0;
       static int h = 0;
      static string raw;
     static int result = 0;

     /* int calculate(string gg)
      {

          int x;
          for (int l = 0; l <= n; l++)
          {
              x =int.Parse(gg.Split(',')[l]);
              if (x <= h)
              {
                  result = result + 1;
              }
              else
              {
                  result = result + 2;
              }
          }
          return (result);
      }*/
        static void Main(string[] args)
        {
            Console.WriteLine("Write The Number Of People:");
            n =int.Parse( Console.ReadLine());
            Console.WriteLine("Enter The Height of the fence:");
            h =int.Parse(Console.ReadLine());
            Console.WriteLine("Enter The Height Of each one  (Put ',' Betw Each one):");
            raw = Console.ReadLine();
             int[] hop = new int[n];

            for (int i = 0; i <= n-1; i++)
            {
                hop[i] =int.Parse(raw.Split(',')[i]);
                if (hop[i] <= h)
                {
                    result = result + 1;
                }
                else
                {
                    result = result + 2;
                }
            }
            Console.WriteLine(result.ToString());
            Console.ReadLine();

        }
    }
}