object Main extends App {
  type Point = (Int, Int)
  type Cost = Int
  type Path = Seq[(Int, Int)]
  val Array(h, w) = io.StdIn.readLine().split(' ').map(_.toInt)
  val field = Array.fill(h)(io.StdIn.readLine().toCharArray)
  val taken = Array.fill(h)(Array.fill(w)(Int.MaxValue))
  val heap = scala.collection.mutable.PriorityQueue.empty[(Point, Cost, Path)](Ordering.by(-_._2))
  heap.enqueue(((0,0), 0, Seq((0, 0))))
  def loop(): Cost = {
    if (heap.isEmpty) -1
    else {
      val ((x, y), cost, path) = heap.dequeue()
      if (x == w-1 && y == h-1) {
        var score = 0
        for (j <- 0 until h; i <- 0 until w; if !path.contains(i, j) && field(j)(i) == '.') score += 1
        score
      } else {
        val nextCost = cost + 1
        Seq((x,y-1),(x,y+1),(x-1,y),(x+1,y))
          .withFilter(p => p._1 >= 0 && p._1 < w && p._2 >= 0 && p._2 < h)
          .withFilter(p => (field(p._2)(p._1) != '#') && nextCost < taken(p._2)(p._1))
          .foreach{p => taken(p._2)(p._1) = nextCost; heap.enqueue((p, nextCost, p +: path))}
        loop()
      }
    }
  }
  println(loop())
}