#include "bits/stdc++.h"

using namespace std;

using i64 = long long;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


template <typename T = i64>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template <typename T = i64>
bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}


signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    for(auto& x : s)
        cin >> x;

    int sx, sy, ex, ey;
    int cnt = 0;
    vector<int> x, y;
    for(int i = 0; i < h; ++i)
        for(int j = 0; j < w; ++j){
            if(s[i][j] == 's'){
                sx = i;
                sy = j;
            }
            if(s[i][j] == 'e'){
                ex = i;
                ey = j;
            }
            if(s[i][j] == 'a'){
                ++cnt;
                x.emplace_back(i);
                y.emplace_back(j);
            }
        }

    x.emplace_back(sx);
    x.emplace_back(ex);
    y.emplace_back(sy);
    y.emplace_back(ey);

    vector<int> dx{1, 0, -1, 0};
    vector<int> dy{0, 1, 0, -1};

    vector<vector<int>> graph(cnt + 2, vector<int>(cnt + 2, MOD));
    for(int i = 0; i < cnt + 2; ++i){
        queue<pair<int,int>> que;
        vector<vector<int>> range(h, vector<int>(w, MOD));
        range[x[i]][y[i]] = 0;
        que.emplace(x[i], y[i]);
        while(!que.empty()){
            int x, y;
            tie(x, y) = que.front();
            que.pop();
            for(int d = 0; d < 4; ++d){
                int nx = x + dx[d];
                int ny = y + dy[d];
                if(nx < 0 || ny < 0 || nx >= h || ny >= w || s[nx][ny] == '#')
                    continue;
                if(chmin(range[nx][ny], range[x][y] + 1))
                    que.emplace(nx, ny);
            }
        }
        for(int j = 0; j < cnt + 2; ++j)
            graph[i][j] = range[x[j]][y[j]];
    }

    vector<vector<i64>> dp(1 << cnt, vector<i64>(cnt, INF));
    for(int i = 0; i < cnt; ++i)
        dp[(1 << i)][i] = graph[cnt][i];

    for(int i = 0; i < (1 << cnt); ++i){
        for(int j = 0; j < cnt; ++j){
            for(int k = 0; k < cnt; ++k){
                chmin(dp[i | (1 << k)][k], dp[i][j] + graph[j][k]);
            }
        }
    }

    i64 ans = INF;
    for(int i = 0; i < (1 << cnt); ++i){
        int cn = __builtin_popcount(i);
        if(cn >= k){
            for(int j = 0; j < cnt; ++j){
                chmin(ans, dp[i][j] + graph[j][cnt + 1]);
            }
        }
    }
    if(ans >= 1e7){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
}


