#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int h, w;
char mp[1000][1000];

bool used[1000][1000];

P ts[22];
int sz;
int dist[20][22];
int memo[1000][1000];
void calc(int sx, int sy,int id) {
	rep(i, h)rep(j, w)used[i][j] = false;
	used[sx][sy] = true; memo[sx][sy] = 0;
	int tmp = 0;
	queue<P> q;
	q.push({ sx,sy });
	while (!q.empty()) {
		tmp++;
		int len = q.size();
		rep(aa, len) {
			P p = q.front(); q.pop();
			int x = p.first, y = p.second;
			rep(k, 4) {
				int nx = x + dx[k], ny = y + dy[k];
				if (nx < 0 || ny < 0 || nx == h || ny == w)continue;
				if (used[nx][ny] || mp[nx][ny] == '#')continue;
				memo[nx][ny] = tmp;
				used[nx][ny] = true;
				q.push({ nx,ny });
			}
		}
	}
	rep(i, sz) {
		int x = ts[i].first, y = ts[i].second;
		if (!used[x][y])dist[id][i] = mod;
		else {
			dist[id][i] = memo[x][y];
		}
	}
}

ll dp[1 << 20][20];
void solve() {
	cin >> h >> w;
	int k; cin >> k;
	int sx, sy, gx, gy;
	vector<P> a;
	rep(i, h)rep(j, w) {
		char t; cin >> t;
		mp[i][j] = t;
		if (t == 's') {
			sx = i, sy = j;
		}
		else if (t == 'e') {
			gx = i,gy = j;
		}
		else if (t == 'a') {
			a.push_back({ i,j });
		}
	}
	int n = a.size(); sz = n + 2;
	rep(i, n) {
		dist[i][i] = 0;
		ts[i] = { a[i].first,a[i].second };
	}
	ts[n] = { sx,sy };
	ts[n + 1] = { gx,gy };
	rep(i, n)calc(a[i].first, a[i].second,i);
	rep(i, a.size()) {
		Rep(j, i + 1, a.size()) {
			//dist[i][j] = calc(a[i].first, a[i].second, a[j].first, a[j].second);
			dist[j][i] = dist[i][j];
		}
	}
	rep(i, (1 << n))rep(j, n)dp[i][j] = mod;
	rep(i, n) {
		dp[1 << i][i] = dist[i][n];
		//dp[1 << i][i] = calc(sx, sy, a[i].first, a[i].second);
	}
	rep1(i, (1 << n)-1) {
		rep(j, n) {
			rep(k, n) {
				if (i&(1 << k))continue;
				int ni = i ^ (1 << k);
				dp[ni][k] = min(dp[ni][k], dp[i][j] + dist[j][k]);
			}
		}
	}
	ll ans = INF;
	vector<int> dg(n);
	rep(i, n) {
		dg[i] = dist[i][n + 1];
		//dg[i] = calc(gx, gy, a[i].first, a[i].second);
	}
	rep(i, (1 << n)) {
		int tmp = 0;
		rep(j, n)if (i&(1 << j))tmp++;
		if (tmp != k)continue;
		rep(j, n) {
			ans = min(ans, dp[i][j] + dg[j]);
		}
	}
	if (ans >= mod)ans = -1;
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(8);
	//init();
	solve();
	stop
		return 0;
}



Measured memory_bytes: 172904