#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#define inf 1e9

using namespace std;
typedef pair<int, int> P;

int h, w, k;
char c[1005][1005];
int px[25], py[25];
int d[1005][1005];
int dist[25][25];
int dp[1<<20][20];
int pop[1<<20];
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

void bfs(int sx, int sy)
{
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			d[x][y] = inf;
		}
	}
	d[sx][sy] = 0;
	
	queue<P> Q;
	Q.push(P(sx, sy));
	
	while(Q.size()){
		int x = Q.front().first, y = Q.front().second;
		Q.pop();
		for(int i = 0; i < 4; i++){
			int nx = x + dx[i], ny = y + dy[i];
			if(nx < 1 || nx > w || ny < 1 || ny > h) continue;
			if(d[nx][ny] < inf) continue;
			if(c[nx][ny] == '#') continue;
			d[nx][ny] = d[x][y] + 1;
			Q.push(P(nx, ny));
		}
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> h >> w >> k;
	int m = 0;
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			cin >> c[x][y];
			if(c[x][y] == 'a') px[m] = x, py[m] = y, m++;
		}
	}
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			if(c[x][y] == 's') px[m] = x, py[m] = y;
			if(c[x][y] == 'e') px[m+1] = x, py[m+1] = y;
		}
	}
	
	for(int i = 0; i <= m+1; i++){
		bfs(px[i], py[i]);
		for(int j = 0; j <= m+1; j++) dist[i][j] = d[px[j]][py[j]];
	}
	
	int M = 1<<m;
	for(int i = 0; i < M; i++){
		for(int j = 0; j < m; j++){
			dp[i][j] = inf;
		}
	}
	for(int i = 0; i < m; i++) dp[1<<i][i] = dist[m][i];
	for(int i = 0; i < M; i++){
		for(int j = 0; j < m; j++){
			for(int k = 0; k < m; k++){
				if(i & (1<<k)) continue;
				dp[i|(1<<k)][k] = min(dp[i|(1<<k)][k], dp[i][j] + dist[j][k]);
			}
		}
	}
	
	for(int i = 1; i < M; i++) pop[i] = pop[i&(i-1)] + 1;
	int ans = inf;
	for(int i = 0; i < M; i++){
		if(pop[i] < k) continue;
		for(int j = 0; j < m; j++){
			ans = min(ans, dp[i][j] + dist[j][m+1]);
		}
	}
	if(ans > inf/2) cout << -1 << endl;
	else cout << ans << endl;
	
	return 0;
}
