### constant

MVS = [[-1, 0, -1], [0, -1, -1], [0, 1, 0], [1, 0, 0]]

### subroutines

def wander_rec(y, x, k, sv)
  if y == $h - 1 && x == $w - 1 && k == 0
    return sv
  end

  max_sv = 0

  for mv in MVS
    y0 = y + mv[0]
    x0 = x + mv[1]
    k0 = k + mv[2]
    if k0 >= 0 && y0 >= 0 && y0 < $h && x0 >= 0 && x0 < $w &&
        $cmaps[y0][x0] >= 0
      dsv = ($visited[y0][x0] == 0) ? $cmaps[y0][x0] : 0

      $visited[y0][x0] += 1
      sv0 = wander_rec(y0, x0, k0, sv + dsv)
      $visited[y0][x0] -= 1

      max_sv = sv0 if max_sv < sv0
    end
  end

  max_sv
end

### main

$h, $w, k = gets.strip.split(' ').map{|s| s.to_i}

$cmaps = $h.times.map{[]}

for y in (0...$h)
  yline = gets.strip

  for x in (0...$w)
    case yline[x]
    when '.'
      $cmaps[y][x] = 0
    when '#'
      $cmaps[y][x] = -1
    else
      $cmaps[y][x] = yline[x].to_i
    end
  end
end
#p $cmaps

$visited = $h.times.map{$w.times.map{0}}

puts wander_rec(0, 0, k, 0)