using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class Point {
        public int x;
        public int y;
        public int count;
        public Point(int x, int y, int count) {
            this.x = x;
            this.y = y;
            this.count = count;
        }
    }

    class MainClass {

        static List<List<bool>> visited;
        static int H;
        static int W;

        public static void Main() {
            H = NextInt();
            W = NextInt();
            visited = new List<List<bool>>();
            for (int i = 0; i < H; i++) {
                visited.Add(Line().Select(x => x == '#').ToList());
            }

            int white = visited.Sum(l => l.Count(x => !x));

            var queue = new Queue<Point>();
            var first = new Point(0, 0, 1);
            queue.Enqueue(first);
            visited[0][0] = true;
            while(queue.Any()) {
                var tmp = queue.Dequeue();
                if(tmp.x == W - 1 && tmp.y == H - 1) {
                    Console.WriteLine(white - tmp.count);
                    return;
                }

                if (tmp.y < H - 1 && !visited[tmp.y + 1][tmp.x]) {
                    visited[tmp.y + 1][tmp.x] = true;
                    queue.Enqueue(new Point(tmp.x, tmp.y + 1, tmp.count + 1));
                }
                if (tmp.y > 0     && !visited[tmp.y - 1][tmp.x]) {
                    visited[tmp.y - 1][tmp.x] = true;
                    queue.Enqueue(new Point(tmp.x, tmp.y - 1, tmp.count + 1));
                }
                if (tmp.x < W - 1 && !visited[tmp.y][tmp.x + 1]) {
                    visited[tmp.y][tmp.x + 1] = true;
                    queue.Enqueue(new Point(tmp.x + 1, tmp.y, tmp.count + 1));
                }
                if (tmp.x > 0     && !visited[tmp.y][tmp.x - 1]) {
                    visited[tmp.y][tmp.x - 1] = true;
                    queue.Enqueue(new Point(tmp.x - 1, tmp.y, tmp.count + 1));
                }
            }

            Console.WriteLine("-1");
        }
    }

    class MyMath {
        static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 13652