object Main extends App {
	private val Empty = Int.MaxValue - 1
	private val Wall = Int.MaxValue

	private def pre(inputs: Seq[String]) = {
		val g = inputs.head.split(' ').map(_.toInt)
		val total = g(0) * g(1)
		val w = inputs.map(_.count(_ == '#')).sum
		val min = solve(inputs)
		val ret = total - w - min - 1
		assert(0 < ret)
		assert(ret < Empty)
		ret
	}

	private def solve(inputs: Seq[String]) = {
		val g = inputs.head.split(' ').map(_.toInt)
		val sy = 1
		val sx = 1
		val gy = g(0)
		val gx = g(1)
		val ffff = inputs.tail.map(_.toCharArray.map(e => if (e == '#') Wall else Empty).toArray).toArray
		val fff = ffff.map(Wall +: _ :+ Wall)
		val wall = fff(0).map(_ => Wall)
		val f = wall +: fff :+ wall

		val q = scala.collection.mutable.Queue[(Int, Int)]()
		q.enqueue((sx, sy))
		f(sy)(sx) = -1
		do {
			val (ny, nx) = q.dequeue()
			if (f(ny)(nx) == -1 || f(ny)(nx) == Empty) {
				//f.foreach(e => println(e.toSeq.filterNot(_ == Empty)))

				f(ny)(nx) = 1 + Math.min(f(ny)(nx),
					Math.min(
						Math.min(f(ny - 1)(nx), f(ny + 1)(nx)),
						Math.min(f(ny)(nx - 1), f(ny)(nx + 1))))

				q.enqueue((ny - 1, nx))
				q.enqueue((ny + 1, nx))
				q.enqueue((ny, nx - 1))
				q.enqueue((ny, nx + 1))

				if (nx == gx && ny == gy) q.clear()
			}
		} while (q.nonEmpty)

		//print("done")
		f(gy)(gx)
	}

	private val s1 =
		"""3 3
			|..#
			|#..
			|...
			|""".stripMargin.split("\r\n")
	private val s2 =
		"""10 37
			|.....................................
			|...#...####...####..###...###...###..
			|..#.#..#...#.##....#...#.#...#.#...#.
			|..#.#..#...#.#.....#...#.#...#.#...#.
			|.#...#.#..##.#.....#...#.#.###.#.###.
			|.#####.####..#.....#...#..##....##...
			|.#...#.#...#.#.....#...#.#...#.#...#.
			|.#...#.#...#.##....#...#.#...#.#...#.
			|.#...#.####...####..###...###...###..
			|.....................................
			|""".stripMargin.split("\r\n")
	private val s3 =
		"""10 37
			|.....................................
			|.....................................
			|.....................................
			|.....................................
			|.....................................
			|.....................................
			|.....................................
			|.....................................
			|.....................................
			|.....................................
			|""".stripMargin.split("\r\n")
	private val s4 =
		"""5 37
			|.....................................
			|####################################.
			|.....................................
			|.####################################
			|.....................................
			|""".stripMargin.split("\r\n")
	//	assert(pre(s1) == 2)
	//	assert(pre(s2) == 209)
	//	assert(pre(s3) == 370 - 10 - 37 + 1)
	//	assert(pre(s4) == 0)

	println(pre(scala.io.Source.stdin.getLines().toSeq))
}
