#include <bits/stdc++.h>
using namespace std;
void map(vector<vector<long long>> s, vector<vector<long long>>& l, long long d,
         long long r, long long n) {
  n++;
  l[d][r] = n;
  long long i, j;
  i = 0;
  j = 1;
  if (s[d + i][r + j] == 0 && l[d + i][r + j] > n) map(s, l, d + i, r + i, n);
  i = 0;
  j = -1;
  if (s[d + i][r + j] == 0 && l[d + i][r + j] > n) map(s, l, d + i, r + i, n);
  i = 1;
  j = 0;
  if (s[d + i][r + j] == 0 && l[d + i][r + j] > n) map(s, l, d + i, r + i, n);
  i = -1;
  j = 0;
  if (s[d + i][r + j] == 0 && l[d + i][r + j] > n) map(s, l, d + i, r + i, n);
}
int main() {
  long long h;
  cin >> h;
  long long w;
  cin >> w;
  h += 2;
  w += 2;
  vector<vector<long long>> s(h, vector<long long>(w, 1));
  long long d, r;
  for (long long i = 1; i < h - 1; i++) {
    for (long long j = 1; j < w - 1; j++) {
      char c;
      cin >> c;
      if (c == '#') {
        s[i][j] = 1;
      } else {
        s[i][j] = 0;
        d = i;
        r = j;
      }
    }
  }
  vector<vector<long long>> l(h, vector<long long>(w, 1e18));
  map(s, l, d, r, 0);
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      if (l[i][j] != 1e18 && l[d][r] < l[i][j]) {
        d = i;
        r = j;
      }
    }
  }
  l = vector<vector<long long>>(h, vector<long long>(w, 1e18));
  map(s, l, d, r, 0);
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      if (l[i][j] != 1e18 && l[d][r] < l[i][j]) {
        d = i;
        r = j;
      }
    }
  }
  cout << l[d][r] - 1 << endl;
  return 0;
}
