#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

const std::vector<std::vector<std::pair<int, int>>>
    peris{
        {{0, 0},
         {1, 0},
         {2, 0},
         {3, 0},
         {0, 1},
         {1, 1},
         {2, 1},
         {0, 2},
         {1, 2},
         {0, 3}},

        {{0, -1},
         {1, -1},
         {2, -1},
         {-1, 0},
         {0, 0},
         {1, 0},
         {2, 0},
         {-1, 1},
         {0, 1},
         {1, 1},
         {-1, 2},
         {0, 2}},

        {{0, -2},
         {1, -2},
         {-1, -1},
         {0, -1},
         {1, -1},
         {-2, 0},
         {-1, 0},
         {0, 0},
         {1, 0},
         {-2, 1},
         {-1, 1},
         {0, 1}},

        {{0, -3},
         {-1, -2},
         {0, -2},
         {-2, -1},
         {-1, -1},
         {0, -1},
         {-3, 0},
         {-2, 0},
         {-1, 0},
         {0, 0}}};

const std::vector<int> ks{10, 12, 12, 10};
constexpr int INF = 1 << 30;

void solve() {
    int h, w, k;
    std::cin >> h >> w >> k;

    std::vector<std::string> ss(h);
    for (auto& s : ss) {
        std::cin >> s;
        for (auto& c : s) {
            if (c == '.') c = '0';
        }
    }

    auto dp = vec(k + 1, vec(1 << 12, vec(h, vec(w, -INF))));
    dp[k][0][0][0] = 0;

    for (int l = k; l >= 0; --l) {
        for (int x = 0; x < h; ++x) {
            for (int y = 0; y < w; ++y) {
                if (ss[x][y] == '#') continue;

                for (int prev = 0; prev < (1 << ks[l]); ++prev) {
                    for (int i = 1; i <= 2; ++i) {
                        int dx = (i & 1),
                            dy = (i >> 1);

                        int nx = x + dx,
                            ny = y + dy;
                        if (nx >= h || ny >= w) continue;

                        int score = dp[l][prev][x][y] + (ss[x][y] - '0');
                        int nprev = prev;
                        for (int j = 0; j < ks[l]; ++j) {
                            if (peris[l][j] != std::make_pair(0, 0)) continue;
                            if ((prev >> j) & 1) score -= (ss[x][y] - '0');
                            nprev |= (1 << j);
                        }

                        int next = 0;
                        for (int j = 0; j < ks[l]; ++j) {
                            auto p = peris[l][j];
                            p.first += dx, p.second += dy;

                            for (int pj = 0; pj < ks[l]; ++pj) {
                                if (p == peris[l][pj]) {
                                    int b = (nprev >> pj) & 1;
                                    next |= (b << j);
                                    break;
                                }
                            }
                        }

                        dp[l][next][nx][ny] = std::max(dp[l][next][nx][ny], score);
                    }

                    if (l == 0) continue;

                    for (int i = 1; i <= 2; ++i) {
                        int dx = (i & 1),
                            dy = (i >> 1);

                        int nx = x - dx,
                            ny = y - dy;
                        if (nx < 0 || ny < 0) continue;

                        int score = dp[l][prev][x][y] + (ss[x][y] - '0');
                        int nprev = prev;
                        for (int j = 0; j < ks[l]; ++j) {
                            if (peris[l][j] != std::make_pair(0, 0)) continue;
                            if ((prev >> j) & 1) score -= (ss[x][y] - '0');
                            nprev |= (1 << j);
                        }

                        int nl = l - 1;
                        int next = 0;
                        for (int j = 0; j < ks[nl]; ++j) {
                            auto p = peris[nl][j];
                            p.first -= dx, p.second -= dy;

                            for (int pj = 0; pj < ks[l]; ++pj) {
                                if (p == peris[l][pj]) {
                                    int b = (nprev >> pj) & 1;
                                    next |= (b << j);
                                    break;
                                }
                            }
                        }

                        dp[nl][next][nx][ny] = std::max(dp[nl][next][nx][ny], score);
                    }
                }
            }
        }
    }

    int ans = 0;
    for (int l = 0; l <= k; ++l) {
        for (int p = 0; p < (1 << ks[l]); ++p) {
            ans = std::max(ans, dp[l][p][h - 1][w - 1]);
        }
    }

    std::cout << ans << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}



Measured memory_bytes: 235808