#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define BACK 6
typedef pair<pair<int,int>, pair<int,int>> PP;

int dp[(1<<(BACK*2))+10][60][60][4];

int main(){
  int h,w,k;
  cin>>h>>w>>k;

  vector<string> vec(h+BACK);
  rep(i,BACK){
    vec[i].resize(w);
    vec[i][0] = '.';
    repl(j,1,w) vec[i][j] = '#';
  }
  rep(i,h) cin>> vec[i+BACK];

  h += BACK;

  fill(dp[0][0][0], dp[1<<(BACK*2)][0][0], -INF);
  dp[0][BACK][0][0] = 0;
  queue<PP> q; // prevs, h, w, k
  q.push(mp(mp(0,BACK), mp(0,0)));

  const int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
  while(!q.empty()){
    PP pp = q.front(); q.pop();
    int prevs = pp.fi.fi;
    int x = pp.fi.se, y = pp.se.fi, kk = pp.se.se;
//dbg(mp(mp(x,y),dp[prevs][x][y][kk]));
    bool visited[4] = {0,0,0,0};
    int px=0, py=0;
    rep(i,BACK){
      int m = (prevs>>(2*i))%4;
      px -= dx[m], py -= dy[m];
      if(px*px + py*py == 1){
        rep(j,4) if(px==dx[j] && py==dy[j]){
          visited[j] = true;
          break;
        }
      }
    }

    rep(i,4){
      int nx = x + dx[i], ny = y + dy[i], nk = kk + (i>=2);
      if(nk>k) continue;
      if(nx<0 || ny<0 || nx>=h || ny>=w || vec[nx][ny]=='#') continue;
//      dbg(mp(nx,ny));
      int ncost = dp[prevs][x][y][kk];
      if(vec[nx][ny]!='.' && !visited[i]) ncost += vec[nx][ny] - '0';
      int nmask = prevs%(1<<(2*(BACK-1)));
      nmask = nmask*4 + i;
      if(dp[nmask][nx][ny][nk] >= ncost) continue;
      dp[nmask][nx][ny][nk] = ncost;
      q.push(mp(mp(nmask,nx), mp(ny,nk)));
    }
  }

  int res = 0;
  rep(i,1<<(BACK*2)) res = max(res, dp[i][h-1][w-1][k]);

  cout << res << endl;

  return 0;
}