import java.util.*

fun main(args: Array<String>) {
    class P(val x: Int, val y: Int, val d: Int)
    val (H, W) = readLine()!!.split(' ').map(String::toInt)
    val field = Array(H){ readLine()!!.toCharArray() }
    val visited = Array(H) { Array(W) {false} }

    val q = ArrayDeque<P>()
    q.push(P(0, 0, 0))
    val totalBlack = field.sumBy { x -> x.filter{c -> c == '#'}.count() }
    var ans = -1;
    val dx = arrayOf(1, 0, -1, 0)
    val dy = arrayOf(0, 1, 0, -1)
    while (!q.isEmpty()) {
        val p = q.poll()
        if (p.y < 0 || p.y >= H || p.x < 0 || p.x >= W) {
            continue
        }
        if (visited[p.y][p.x]) continue
        visited[p.y][p.x] = true
//        println("${p.x} ${p.y} ${p.d} $totalBlack")
        if (p.y == H-1 && p.x == W -1) {
            ans = H * W - p.d - 1 - totalBlack
            break
        }
        if (field[p.y][p.x] == '#') {
            continue
        }
        dx.zip(dy).forEach { pair ->
            val dx = pair.first
            val dy = pair.second
            q.add(P(p.x + dx, p.y + dy, p.d + 1))
        }
    }
    println(ans)
}
