#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;

#define INF 1145141919

typedef pair<int, int> P;
int H, W, K;
int map[60][60];
int dp[50][50][4][2048];

bool f(int s, int t) {
  return s & (1 << (t-1));
}

int main() {
  cin >> H >> W >> K;
  for (int y=0; y<H; y++) {
    for (int x=0; x<W; x++) {
      char c;
      cin >> c;
      map[x][y] = c == '#' ? -1 : c == '.' ? 0 : (int)c-(int)'0';
    }
  }
  for (int x=0; x<W; x++) {
    for (int y=0; y<H; y++) {
      for (int k=0; k<=K; k++) {
        for (int s=0; s<2048; s++) {
          dp[x][y][k][s] = -INF;
        }
      }
    }
  }
  dp[0][0][0][0] = 0;
  queue< pair<P, P> > q;
  q.push(make_pair(P(0, 0), P(0, 0)));

  while (!q.empty()) {
    int x = q.front().first.first, y = q.front().first.second,
        k = q.front().second.first, s = q.front().second.second; q.pop();
    if (x < W-1 && map[x+1][y] != -1) {
      int ns = 0;
      if (k == 0) ns = (1<<1)*f(s,3) | (1<<3)*f(s,5) | (1<<4)*f(s,6) | (1<<6)*f(s,8) | (1<<7)*f(s,9) | (1<<8);
      if (k == 1) ns = (1<<0)*f(s,2) | (1<<2)*f(s,4) | (1<<3)*f(s,5) | (1<<5)*f(s,7) | (1<<6) | (1<<8)*f(s,10) | (1<<9)*f(s,11);
      if (k == 2) ns = (1<<0)*f(s,2) | (1<<1)*f(s,3) | (1<<3) | (1<<4)*f(s,6) | (1<<6)*f(s,8) | (1<<7)*f(s,9) | (1<<9)*f(s,11);
      if (k == 3) ns = (1<<0)*f(s,2) | (1<<1)*f(s,3) | (1<<3)*f(s,5) | (1<<4)*f(s,6) | (1<<6)*f(s,8);
      bool t = (k==1 && f(s,8)) || (k==2 && f(s,5)) || (k==3 && f(s,1));
      if (dp[x+1][y][k][ns] < dp[x][y][k][s] + (t?0:map[x+1][y])) {
        dp[x+1][y][k][ns] = dp[x][y][k][s] + (t?0:map[x+1][y]);
        q.push(make_pair(P(x+1, y), P(k, ns)));
      }
    }
    if (y < H-1 && map[x][y+1] != -1) {
      int ns = 0;
      if (k == 0) ns = (1<<0)*f(s,3) | (1<<1)*f(s,5) | (1<<2)*f(s,6) | (1<<3)*f(s,8) | (1<<4)*f(s,9) | (1<<5);
      if (k == 1) ns = (1<<0)*f(s,4) | (1<<1)*f(s,5) | (1<<2)*f(s,7) | (1<<3) | (1<<4)*f(s,8) | (1<<5)*f(s,9) | (1<<6)*f(s,10);
      if (k == 2) ns = (1<<0) | (1<<1)*f(s,5) | (1<<2)*f(s,6) | (1<<3)*f(s,7) | (1<<4)*f(s,9) | (1<<6)*f(s,10) | (1<<7)*f(s,11);
      if (k == 3) ns = (1<<0)*f(s,5) | (1<<1)*f(s,6) | (1<<3)*f(s,7) | (1<<4)*f(s,8) | (1<<6)*f(s,9);
      bool t = (k==1 && f(s,11)) || (k==2 && f(s,8)) || (k==3 && f(s,4));
      if (dp[x][y+1][k][ns] < dp[x][y][k][s] + (t?0:map[x][y+1])) {
        dp[x][y+1][k][ns] = dp[x][y][k][s] + (t?0:map[x][y+1]);
        q.push(make_pair(P(x, y+1), P(k, ns)));
      }
    }
    if (k < K && x > 0 && map[x-1][y] != -1) {
      int ns = 0;
      if (k == 0) ns = (1<<0)*f(s,2) | (1<<1)*f(s,3) | (1<<2)*f(s,4) | (1<<3)*f(s,5) | (1<<4)*f(s,6) | (1<<5)*f(s,7) | (1<<6)*f(s,8) | (1<<7);
      if (k == 1) ns = (1<<0)*f(s,3) | (1<<1)*f(s,4) | (1<<2)*f(s,5) | (1<<3)*f(s,6) | (1<<4) | (1<<5)*f(s,8) | (1<<6)*f(s,9) | (1<<7)*f(s,10) | (1<<8)*f(s,11);
      if (k == 2) ns = (1<<0) | (1<<1)*f(s,5) | (1<<2)*f(s,6) | (1<<3)*f(s,7) | (1<<4)*f(s,8) | (1<<5)*f(s,9) | (1<<6)*f(s,10) | (1<<7)*f(s,11);
      bool t = (k==0 && f(s,9)) || (k==1 && f(s,7)) || (k==2 && f(s,4));
      if (dp[x-1][y][k+1][ns] < dp[x][y][k][s] + (t?0:map[x-1][y])) {
        dp[x-1][y][k+1][ns] = dp[x][y][k][s] + (t?0:map[x-1][y]);
        q.push(make_pair(P(x-1, y), P(k+1, ns)));
      }
    }
    if (k < K && y > 0 && map[x][y-1] != -1) {
      int ns = 0;
      if (k == 0) ns = (1<<0)*f(s,1) | (1<<2)*f(s,2) | (1<<3)*f(s,3) | (1<<5)*f(s,4) | (1<<6)*f(s,5) | (1<<8)*f(s,8) | (1<<9)*f(s,9) | (1<<10);
      if (k == 1) ns = (1<<0)*f(s,1) | (1<<1)*f(s,2) | (1<<3)*f(s,3) | (1<<4)*f(s,5) | (1<<6)*f(s,7) | (1<<7) | (1<<8)*f(s,8) | (1<<9)*f(s,10) | (1<<10)*f(s,11);
      if (k == 2) ns = (1<<1)*f(s,2) | (1<<2)*f(s,3) | (1<<3) | (1<<4)*f(s,5) | (1<<5)*f(s,6) | (1<<6)*f(s,8) | (1<<7)*f(s,9) | (1<<8)*f(s,11);
      bool t = (k==0 && f(s,6)) || (k==1 && f(s,4)) || (k==2 && f(s,1));
      if (dp[x][y-1][k+1][ns] < dp[x][y][k][s] + (t?0:map[x][y-1])) {
        dp[x][y-1][k+1][ns] = dp[x][y][k][s] + (t?0:map[x][y-1]);
        q.push(make_pair(P(x, y-1), P(k+1, ns)));
      }
    }
  }
  int ans = 0;
  for (int k=0; k<=K; k++) {
    for (int s=0; s<(k==0||k==3?512:2048); s++) {
      ans = max(ans, dp[W-1][H-1][k][s]);
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 83228