import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format, std.datetime;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long H, W;
    scan(H, W);
    auto S = new string[](H);
    foreach (i; 0 .. H)
        S[i] = sread();
    long black;
    foreach (i; 0 .. H)
        foreach (j; 0 .. W)
            if (S[i][j] == '#')
                black++;
    DList!(Tuple!(long, long)) Q;
    Q.insert(Tuple!(long, long)(0, 0));
    auto dist = new long[][](H, W);
    foreach (i; 0 .. H)
        foreach (j; 0 .. W)
            dist[i][j] = -1;
    dist[0][0] = 1;
    while (!Q.empty)
    {
        auto t = Q.front;
        Q.removeFront();
        if (S[t[0]][t[1]] == '#')
            continue;
        if (t[0] != 0 && dist[t[0] - 1][t[1]] == -1)
        {
            dist[t[0] - 1][t[1]] = dist[t[0]][t[1]] + 1;
            Q.insert(Tuple!(long, long)(t[0] - 1, t[1]));
        }
        if (t[1] != 0 && dist[t[0]][t[1] - 1] == -1)
        {
            dist[t[0]][t[1] - 1] = dist[t[0]][t[1]] + 1;
            Q.insert(Tuple!(long, long)(t[0], t[1] - 1));
        }
        if (t[0] != H - 1 && dist[t[0] + 1][t[1]] == -1)
        {
            dist[t[0] + 1][t[1]] = dist[t[0]][t[1]] + 1;
            Q.insert(Tuple!(long, long)(t[0] + 1, t[1]));
        }
        if (t[1] != W - 1 && dist[t[0]][t[1] + 1] == -1)
        {
            dist[t[0]][t[1] + 1] = dist[t[0]][t[1]] + 1;
            Q.insert(Tuple!(long, long)(t[0], t[1] + 1));
        }
    }
    writeln(H * W - dist[H - 1][W - 1] - black);
}
