#include <bits/stdc++.h>
#include <numeric>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   //最大値を求める
#define MIN(x) *min_element(ALL(x))   //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back // vectorヘの挿入
#define mp make_pair    // pairのコンストラクタ
#define F first         // pairの一つ目の要素
#define S second        // pairの二つ目の要素

#define pcnt __builtin_popcount
#define pcntll(x) __builtin_popcountll(x)

#define perm(c)                                                                \
    sort(all(c));                                                              \
    for (bool c##p = 1; c##p;                                                  \
         c##p = next_permutation(all(c))) //順列 123 132 213 231 312 321

#define bit(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << " " << p.second;
    return os;
}

template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) {
        os << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return os;
}

template <typename T> istream &operator>>(istream &is, vector<T> &v) {
    for (T &in : v)
        is >> in;
    return is;
}

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int R, C, H, W, N;

const int dx61[6] = {-1, -1, -1, 0, 0, 1};
const int dy61[6] = {-1, 0, 1, 1, -1, 0};

const int dx62[6] = {-1, 0, 0, 1, 1, 1};
const int dy62[6] = {0, 1, -1, -1, 0, 1};

int used[200][200];

struct pos {
    int x, y, dist;
    //    pos &operator=(const pos &rh) {
    //        x = rh.x;
    //        y = rh.y;
    //        dist = rh.dist;
    //    }
} Pos;

pos s, g;

signed main() {

    cin >> H >> W;
    vector<string> Map(H);

    int whiteCount = 0;
    rep(i, H) {
        cin >> Map[i];
    }

    rep(i, H) {
        rep(j, W) {
            if(Map[i][j] == '.') whiteCount ++;
        }
    }
    
    PRINT(whiteCount)
    bool ok = false;
    queue<pos> que;
    que.push({0, 0, 0});
    used[0][0] = true;
    while (!que.empty() && !ok) {
        auto now = que.front();
        que.pop();
        rep(j, 4) {
            int nx = now.x + dx[j];
            int ny = now.y + dy[j];
            if (nx < 0 || nx >= W  || ny < 0 || ny >= H || Map[ny][nx] =='#' || used[nx][ny] == true) {
                continue;
            }
            if(nx == W-1 && ny == H-1){
                PRINT("FIN")
                PRINT(now.dist)
                whiteCount -= now.dist + 2;
                ok = true;
                break;
            }
            used[nx][ny] = true;
            que.push({nx, ny, now.dist + 1});
        }
    }
    if(!ok) whiteCount = -1;
    cout << whiteCount << endl;
}


Measured memory_bytes: 256