#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 60 + 10;
char g[N][N];
bool vis[N][N];
int n, m, h;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
struct Node {
int x,y,th,ans;
};
int bfs() {
queue<Node> q;
q.push({0,0,h,0});
vis[0][0] = 1;
int res = 1e9;
while(q.size()) {
Node t = q.front();
q.pop();
//printf("%d %d %d %d\n",t.x+1,t.y+1,t.th,t.ans);
if(t.x == n - 1 && t.y == m - 1 && t.th > 0) {
res = min(res, t.ans);
} else {
for(int i = 0 ; i < 4 ; ++i) {
int nx = t.x + dx[i];
int ny = t.y + dy[i];
if(nx >= 0 && nx <= n -1 && ny >= 0 && ny <= m - 1 &&!vis[nx][ny] && g[nx][ny]!='*') {
int a = g[nx][ny] - '0';
if(a <= 9 && a >= 1) {
if(t.th - a > 0) {
q.push({nx,ny,t.th - a,t.ans + 1});
vis[nx][ny] = 1;
}
} else {
q.push({nx,ny,t.th,t.ans+1});
vis[nx][ny] = 1;
}
}
}
}
}
return res;
}
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif
scanf("%d%d%d",&n,&m,&h);
for(int i = 0 ; i < n ; ++i)
scanf("%s",g[i]);
int ans = bfs();
if(ans == 1e9)ans = -1;
printf("%d",ans);
return 0;
}