void main() {
    int[] tmp = readln.split.to!(int[]);
    int h = tmp[0], w = tmp[1];

    int cnt;
    string[] s = new string[h];
    foreach (i; 0 .. h) {
        s[i] = readln.chomp;
        cnt += s[i].count('.');
    }

    int[] dy = [-1, 0, 1, 0], dx = [0, 1, 0, -1];

    int[][] dist = new int[][](h, w);
    foreach (d; dist) {
        d[] = -1;
    }
    dist[0][0] = 0;

    coord[] que;
    que ~= coord(0, 0);

    while (!que.empty) {
        int y1 = que[0].y, x1 = que[0].x;
        que.popFront;
        foreach (dir; 0 .. 4) {
            int y2 = y1 + dy[dir], x2 = x1 + dx[dir];
            if (y2 < 0 || h <= y2 || x2 < 0 || w <= x2) continue;
            if (s[y2][x2] == '#') continue;

            if (dist[y2][x2] == -1) {
                que ~= coord(y2, x2);
                dist[y2][x2] = dist[y1][x1] + 1;
            }
        }
    }

    writeln(dist[h-1][w-1] != -1 ? cnt - dist[h-1][w-1] - 1 : dist[h-1][w-1]);
}

alias Tuple!(int, "y", int, "x") coord;

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;