import std.stdio;
import std.string;
import std.algorithm;
import std.conv;
import std.array;
import std.range;
import std.c.stdio;
import core.memory;

int h,w,k;
int[][] board;

int[][] dp;
ref int getdp(int l,int a,int b,int c,int d,int e,int y,int x){
	return dp[l][((((((a*4+b)*4)+c)*4+d)*4+e)*h+y)*w+x];
}

void main(){
	//GC.disable;
	scanf("%d %d %d",&h,&w,&k);
	dp = new int[][](k+1,4*4*4*4*4*h*w);
	foreach(int g;0..k+1){
		dp[g][] = int.min;
	}
	char[] rbuf = new char[64];
	board = new int[][](h,w);
	std.stdio.stdin.flush;
	foreach(int i;0..h){
		readln(rbuf);
		foreach(int j;0..w){
			if(rbuf[j] == '#')
				board[i][j] = -1;
			else if(rbuf[j] == '.')
				board[i][j] = 0;
			else
				board[i][j] = rbuf[j]-'0';
		}
	}
	int[5][1024] dirs;
	int[1024] backc;
	backc[] = 0;
	foreach(int i;0..1024){
		foreach(int j;0..5){
			int d = (i / (1<<(j*2)))%4;
			dirs[i][j] = d;
			if(d<2)
				backc[i]++;
		}
	}
	int[4] dx = [0,-1,0,1];
	int[4] dy = [-1,0,1,0];
	foreach(i;0..1024){
		dp[0][i*w*h] = 0;
	}
	foreach(int g;0..k+1){
		foreach(int i;0..h){
			foreach(int j;0..w){
				foreach(int t;0..1024){
					foreach(int d;0..4){
						if(d<2 && g == k)
							continue;
						if(i+dy[d]>=0&&i+dy[d]<h&&j+dx[d]>=0&&j+dx[d]<w){
							if(board[i+dy[d]][j+dx[d]]>=0){
								int pls = board[i+dy[d]][j+dx[d]];
								int nx=j;
								int ny=i;
								foreach(p;0..5){
									nx += dx[(dirs[t][p]+2)%4];
									ny += dy[(dirs[t][p]+2)%4];
									if(ny == i+dy[d] && nx == j+dx[d]){
										pls = 0;
									}
								}
								getdp(g + (d<2?1:0),dirs[t][3],dirs[t][2],dirs[t][1],dirs[t][0],d,i+dy[d],j+dx[d]) = max(getdp(g + (d<2?1:0),dirs[t][3],dirs[t][2],dirs[t][1],dirs[t][0],d,i+dy[d],j+dx[d]),dp[g][t*h*w+i*w+j] + pls);
							}
						}
					}
				}
			}
		}
	}
	/*foreach(g;0..k+1){
		g.writeln;
		foreach(i;0..h){
			int[] tmpline;
			foreach(j;0..w){
				int tmpmax=0;
				foreach(t;0..1024){
					if(backc[t] == g)
						tmpmax = max(tmpmax,dp[g][t*w*h+i*w+j]);
				}
				tmpline ~= tmpmax;
			}
			tmpline.writeln;
		}
	}*/
	int res=0;
	foreach(int g;0..k+1){
		foreach(int i;0..1024){
			res = max(res,dp[g][i*h*w+(h-1)*w+w-1]);
		}
	}
	res.writeln;
}