#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e15;
bool d[22][22];
long long mp[22][22];
vector<long long> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
int main() {
  long long H, W;
  cin >> H >> W;
  for (long long i = 1; i < H + 1; i++) {
    string S;
    cin >> S;
    for (long long j = 1; j < W + 1; j++)
      if (S.at(j - 1) == '.') d[i][j] = true;
  }
  long long Start = H * 23 + 1, Goal = 23 + W;
  for (long long i = 0; i < 22; i++)
    for (long long j = 0; j < 22; j++) mp[i][j] = -1;
  mp[H][1] = 0;
  queue<long long> Q;
  Q.push(Start);
  while (!Q.empty()) {
    long long X = Q.front();
    Q.pop();
    long long h = X / 23, w = X % 23;
    for (long long i = 0; i < 4; i++) {
      long long hh = h + dx.at(i), ww = w + dy.at(i);
      if (d[hh][ww]) {
        if (mp[hh][ww] == -1) {
          mp[hh][ww] = mp[h][w] + 1;
          Q.push(hh * 23 + ww);
        }
      }
    }
  }
  cout << mp[1][W] << endl;
}
