#include<bits/stdc++.h>
using namespace std;
inline void ChMax(int& a, int b){ a = max(a, b); }

const int dy[] = {-1, 0, 0, 1}, dx[] = {0, -1, 1, 0};
const int bitMask = (1 << 12) - 1;
int H, W, K;
char S[50][50];
int dp[50][50][1 << 12];
bool Visited[1 << 12];



int main()
{
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < (1 << 12); i++) {
    int nx = 0, ny = 0, bit = i;
    for(int j = 0; j < 6; j++, bit >>= 2) {
      nx -= dx[bit & 3], ny -= dy[bit & 3];
      if (nx == 0 && ny == 0) Visited[i] = true;
    }
  }

  cin >> H >> W >> K;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }

  dp[0][0][bitMask] = 0;

  for(int m = K; m >= 0; m--) {
    int notnext = m == 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        for (int k = 0; k < (1 << 12); k++) {
          if (dp[i][j][k] == -1) continue;
          int Get = 0;
          if (isdigit(S[i][j]) && !Visited[k]) Get += S[i][j] - '0';
          for (int l = notnext << 1; l < 4; l++) {
            int ny = i + dy[l], nx = j + dx[l];
            if (ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
            if (S[ny][nx] == '#')                       continue;
            ChMax(dp[ny][nx][((k << 2) | l) & bitMask], dp[i][j][k] + Get);
          }
        }
      }
    }
  }
  cout << *max_element(dp[H - 1][W - 1], dp[H - 1][W]) << endl;
}