#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll H, W, K;
string field[1005];
vector<i_i> Apples;
int sh, sw, gh, gw;
ll dist[22][22];
ll DIST[1005][1005];
ll sdist[22], gdist[22];
ll dp[1 << 20][20];
int dh[4] = {1, -1, 0, 0};
int dw[4] = {0, 0, 1, -1};
void search(int index) {
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            DIST[h][w] = 1e9;
        }
    }
    i_i start = Apples[index];
    DIST[start.first][start.second] = 0;
    queue<i_i> que;
    que.push(start);
    while(!que.empty()) {
        i_i now = que.front();
        int nowh = now.first;
        int noww = now.second;
        que.pop();
        for(int i = 0; i < 4; i++) {
            int newh = nowh + dh[i];
            int neww = noww + dw[i];
            if(newh < 0 or newh >= H) continue;
            if(neww < 0 or neww >= W) continue;
            if(field[newh][neww] == '#') continue;
            if(chmin(DIST[newh][neww], DIST[nowh][noww] + 1)) {
                que.push({newh, neww});
            }
        }
    }
    for(int i = 0; i < Apples.size(); i++) {
        ll d = DIST[Apples[i].first][Apples[i].second];
        dist[index][i] = d;
        //cerr << d << " ";
    }
    sdist[index] = DIST[sh][sw];
    gdist[index] = DIST[gh][gw];
    //cerr << endl;
}

ll counter(ll x) {
    if(x == 0) return 0;
    return (x & 1) + (counter(x/ 2));
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W >> K;
    for(int h = 0; h < H; h++) {
        cin >> field[h];
        for(int w = 0; w < W; w++) {
            if(field[h][w] == 's') {
                sh = h;
                sw = w;
            }
            if(field[h][w] == 'e') {
                gh = h;
                gw = w;
            }
            if(field[h][w] == 'a') {
                Apples.emplace_back(h, w);
            }
        }
    }
    ll ans = 1e18;
    for(int i = 0; i <= 20; i++) {
        for(int j = 0; j < (1 << 20); j++) {
            dp[j][i] = 1e18;
        }
    }
    for(int i = 0; i < Apples.size(); i++) {
        search(i);
        dp[1 << i][i] = sdist[i];
    }
    for(int bits = 1; bits < (1 << Apples.size()); bits++) {
        for(int i = 0; i < Apples.size(); i++) {
            if(!(bits & (1 << i))) continue;
            //cerr << bits << " " << i << " " << dp[bits][i] << endl;
            if(counter(bits) >= K) {
                chmin(ans, dp[bits][i] + gdist[i]);
            }
            for(int j = 0; j < Apples.size(); j++) {
                if(bits & (1 << j)) continue;
                chmin(dp[bits | (1 << j)][j], dp[bits][i] + dist[i][j]);
            }
        }
    }
    if(ans >= 1e9) ans = -1;
    cout << ans << endl;
    return 0;
}

