#include<bits/stdc++.h>
using namespace std;

void solve();

int H,W,K;
int fid[60][60] = {0};
int dp[60][60][5][4][4][4][4][4];
int dx[] = {0,1,0,-1},dy[] = {1,0,-1,0};
int mem[] = {1,10,-1,-10};

int main()
{
    scanf("%d%d%d",&H,&W,&K);
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            char C;
            scanf(" %c",&C);
            if('1' <= C <= '9')
            {
                fid[i][j] = C - '0';
            }
            if(C == '#')
            {
                fid[i][j] = -1;
            }
            if(C == '.')
            {
                fid[i][j] = 0;
            }
        }
    }
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            for(int k = 0; k < K + 1; k++)
            {
                for(int a = 0; a < 4; a++)
                {
                    for(int b = 0; b < 4; b++)
                    {
                        for(int c = 0; c < 4; c++)
                        {
                            for(int d = 0; d < 4; d++)
                            {
                                for(int e = 0; e < 4; e++)
                                {
                                    dp[i][j][k][a][b][c][d][e] = -1;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    solve();
    return 0;
}

void solve()
{
    dp[0][0][0][0][0][0][0][0] = fid[0][0];
    for(int k = 0; k < K + 1; k++)
    {
        for(int i = 0; i < H; i++)
        {
            for(int j = 0; j < W; j++)
            {
                for(int a = 0; a < 4; a++)
                {
                    for(int b = 0; b < 4; b++)
                    {
                        for(int c = 0; c < 4; c++)
                        {
                            for(int d = 0; d < 4; d++)
                            {
                                for(int e = 0; e < 4; e++)
                                {
                                    if(dp[i][j][k][a][b][c][d][e] == -1)continue;
                                    for(int f = 0; f < 4; f++)
                                    {
                                        int X = i + dx[f],Y = j + dy[f];
                                        if(X < 0 || H <= X || Y < 0 || W <= Y || fid[X][Y] == -1)continue;
                                        if(f < 2)
                                        {
                                            if(!(mem[f] + mem[e]) || !(mem[f] + mem[e] + mem[d] + mem[c]) || !(mem[f] + mem[e] + mem[d] + mem[c] + mem[b] + mem[a]))
                                            {
                                                dp[X][Y][k][b][c][d][e][f] = max(dp[X][Y][k][b][c][d][e][f],dp[i][j][k][a][b][c][d][e]);
                                            }
                                            else
                                            {
                                                dp[X][Y][k][b][c][d][e][f] = max(dp[X][Y][k][b][c][d][e][f],dp[i][j][k][a][b][c][d][e] + fid[X][Y]);
                                            }
                                        }
                                        else
                                        {
                                            if(k == K)continue;
                                            if(!(mem[f] + mem[e]) || !(mem[f] + mem[e] + mem[d] + mem[c]) || !(mem[f] + mem[e] + mem[d] + mem[c] + mem[b] + mem[a]))
                                            {
                                                dp[X][Y][k + 1][b][c][d][e][f] = max(dp[X][Y][k + 1][b][c][d][e][f],dp[i][j][k][a][b][c][d][e]);
                                            }
                                            else
                                            {
                                                dp[X][Y][k + 1][b][c][d][e][f] = max(dp[X][Y][k + 1][b][c][d][e][f],dp[i][j][k][a][b][c][d][e] + fid[X][Y]);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int ans = 0;
    for(int a = 0; a < 4; a++)
    {
        for(int b = 0; b < 4; b++)
        {
            for(int c = 0; c < 4; c++)
            {
                for(int d = 0; d < 4; d++)
                {
                    for(int e = 0; e < 4; e++)
                    {
                        ans = max(ans,dp[H - 1][W - 1][K][a][b][c][d][e]);
                    }
                }
            }
        }
    }
    printf("%d\n",ans);
    return;
}

Measured memory_bytes: 53212