#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 1005

struct LOC{
	void set(int arg_row,int arg_col){
		row = arg_row;
		col = arg_col;
	}
	int row,col;
};

struct Info{
	Info(int arg_row,int arg_col,int arg_sum_dist){
		row = arg_row;
		col = arg_col;
		sum_dist = arg_sum_dist;
	}
	int row,col,sum_dist;
};

int H,W,K;
int start = 0,goal = 1;
int diff_row[4] = {-1,0,0,1},diff_col[4] = {0,-1,1,0};
int work[SIZE][SIZE];
int min_dist[25][25],POW[25];
int dp[20][1 << 20];
char table[SIZE][SIZE];
LOC loc[25];


bool rangeCheck(int row,int col){

	return row >= 0 && row <= H-1 && col >= 0 && col <= W-1;
}


int main(){

	POW[0] = 1;
	for(int i = 1; i < 25; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%d %d %d",&H,&W,&K);

	int index = 2;

	for(int row = 0; row < H; row++){

		scanf("%s",table[row]);
		for(int col = 0; col < W; col++){
			switch(table[row][col]){
			case 's':
				loc[start].set(row,col);
				break;

			case 'e':
				loc[goal].set(row,col);
				break;

			case 'a':
				loc[index].set(row,col);
				index++;
				break;

			default:
				//Do nothing
				break;
			}
		}
	}

	queue<Info> Q;

	for(int start = 0; start < index; start++){

		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				work[row][col] = BIG_NUM;
			}
		}

		work[loc[start].row][loc[start].col] = 0;
		Q.push(Info(loc[start].row,loc[start].col,0));

		while(!Q.empty()){

			if(Q.front().sum_dist > work[Q.front().row][Q.front().col]){

				Q.pop();

			}else{

				for(int i = 0; i < 4; i++){

					int adj_row = Q.front().row+diff_row[i];
					int adj_col = Q.front().col+diff_col[i];
					int next_dist = Q.front().sum_dist+1;

					if(rangeCheck(adj_row,adj_col) == false || table[adj_row][adj_col] == '#' ||
							work[adj_row][adj_col] <= next_dist)continue;

					work[adj_row][adj_col] = next_dist;
					Q.push(Info(adj_row,adj_col,next_dist));
				}

				Q.pop();
			}
		}

		for(int next = 0; next < index; next++){

			min_dist[start][next] = work[loc[next].row][loc[next].col];
		}
	}

	int ans = BIG_NUM;
	int num_apple = index-2,offset=2;

	for(int i = 0; i < num_apple; i++){
		for(int state = 0; state < POW[num_apple]; state++){
			dp[i][state] = BIG_NUM; //dp[最後のリンゴ][状態] = 最小コスト
		}
	}

	for(int i = 0; i < num_apple; i++){

		dp[i][POW[i]] = min_dist[start][i+offset];
	}

	int tmp;

	for(int state = 1; state < POW[num_apple]; state++){
		for(int i = 0; i < num_apple; i++){
			if(dp[i][state] == BIG_NUM)continue;

			tmp = 0;
			for(int loop = 0; loop < num_apple; loop++){
				if(state & (1 << loop))tmp++;
			}

			if(tmp == K){

				ans = min(ans,dp[i][state]+min_dist[i+offset][goal]);
				continue; //寄り道するのは無駄なので以後遷移は不要
			}

			for(int loop = 0; loop < num_apple; loop++){
				if(state & (1 << loop)){

					//Do nothing

				}else{
					int next_state = state+POW[loop];
					int next_dist = dp[i][state]+min_dist[i+offset][loop+offset];

					dp[loop][next_state] = min(dp[loop][next_state],next_dist);
				}
			}
		}
	}


	if(ans == BIG_NUM){

		printf("-1\n");
	}else{

		printf("%d\n",ans);
	}

	return 0;
}



Measured memory_bytes: 90116