using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.D
{
    public class Program
    {
        public static long H { get; private set; }
        public static long W { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            (H, W) = Read2Longs();
            var table_isBlack = new bool[H, W];
            var blackCount = 0L;
            for (int i = 0; i < H; i++)
            {
                var l = ReadText();
                for (int j = 0; j < W; j++)
                {
                    var isBlack = l[j] == '#';
                    table_isBlack[i, j] = isBlack;
                    if (isBlack) blackCount++;
                }
            }

            // 最短経路を求めて、通らなかった白マスを黒にぬればよい
            var step = CreateStepTable();
            step[0, 0] = 0;
            var queue = new Queue<Point>();
            queue.Enqueue(new Point(0, 0));
            while (queue.Count > 0)
            {
                var p = queue.Dequeue();

                var nextPonints = new Point[]
                {
                    new Point(p.H + 1, p.W),
                    new Point(p.H - 1, p.W),
                    new Point(p.H, p.W + 1),
                    new Point(p.H, p.W - 1),
                };

                foreach (var next in nextPonints)
                {
                    if (next.H < 0 || next.H == H) continue;
                    if (next.W < 0 || next.W == W) continue;
                    if (table_isBlack[p.H, p.W]) continue;
                    // 到達済みの場合
                    if (step[next.H, next.W] != -1) continue;

                    queue.Enqueue(next);
                    step[next.H, next.W] = step[p.H, p.W] + 1;
                }
            }

            var shortestStep = step[H - 1, W - 1];
            if (shortestStep == -1) return -1;

            return H * W - blackCount - (shortestStep + 1);
        }

        private static long[,] CreateStepTable()
        {
            var t = new long[H, W];
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    t[i, j] = -1;
                }
            }

            return t;
        }

        class Point
        {
            public int H { get; set; }
            public int W { get; set; }

            public Point(int h, int w)
            {
                H = h;
                W = w;
            }
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 28596