#include <bits/stdc++.h>
using namespace std;
vector<string> stage;
long long H, W;
long long foo[25][25];
long long bar[25][25];
void solve() {
  cin >> H >> W;
  for (long long h = 0; h < (H); h++) {
    string s;
    cin >> s;
    stage.push_back(s);
  }
  long long h = 0;
  long long w = 0;
  while (true) {
    if (stage[h][w] == '.') break;
    h++;
    if (h == H) {
      h = 0;
      w++;
    }
  }
  for (long long i = 0; i < (25); i++)
    for (long long j = 0; j < (25); j++) foo[i][j] = -1;
  for (long long i = 0; i < (25); i++)
    for (long long j = 0; j < (25); j++) bar[i][j] = -1;
  queue<pair<pair<long long, long long>, long long>> q;
  q.push(make_pair(make_pair(h, w), 0));
  foo[h][w] = 0;
  long long foo_c = -1;
  long long foo_h = 0;
  long long foo_w = 0;
  while (q.size()) {
    auto tmp = q.front();
    q.pop();
    long long tmp_h = tmp.first.first;
    long long tmp_w = tmp.first.second;
    long long tmp_c = tmp.second;
    if (tmp_c > foo_c) {
      foo_c = tmp_c;
      foo_h = tmp_h;
      foo_w = tmp_w;
    }
    if (tmp_h > 0 and stage[tmp_h - 1][tmp_w] == '.' and
        foo[tmp_h - 1][tmp_w] == -1) {
      foo[tmp_h - 1][tmp_w] = tmp_c + 1;
      q.push(make_pair(make_pair(tmp_h - 1, tmp_w), tmp_c + 1));
    }
    if (tmp_h < H - 1 and stage[tmp_h + 1][tmp_w] == '.' and
        foo[tmp_h + 1][tmp_w] == -1) {
      foo[tmp_h + 1][tmp_w] = tmp_c + 1;
      q.push(make_pair(make_pair(tmp_h + 1, tmp_w), tmp_c + 1));
    }
    if (tmp_w > 0 and stage[tmp_h][tmp_w - 1] == '.' and
        foo[tmp_h][tmp_w - 1] == -1) {
      foo[tmp_h][tmp_w - 1] = tmp_c + 1;
      q.push(make_pair(make_pair(tmp_h, tmp_w - 1), tmp_c + 1));
    }
    if (tmp_w < W - 1 and stage[tmp_h][tmp_w + 1] == '.' and
        foo[tmp_h][tmp_w + 1] == -1) {
      foo[tmp_h][tmp_w + 1] = tmp_c + 1;
      q.push(make_pair(make_pair(tmp_h, tmp_w + 1), tmp_c + 1));
    }
  }
  q.push(make_pair(make_pair(foo_h, foo_w), 0));
  bar[foo_h][foo_w] = 0;
  long long bar_c = -1;
  while (q.size()) {
    auto tmp = q.front();
    q.pop();
    long long tmp_h = tmp.first.first;
    long long tmp_w = tmp.first.second;
    long long tmp_c = tmp.second;
    if (tmp_c > bar_c) {
      bar_c = tmp_c;
    }
    if (tmp_h > 0 and stage[tmp_h - 1][tmp_w] == '.' and
        bar[tmp_h - 1][tmp_w] == -1) {
      bar[tmp_h - 1][tmp_w] = tmp_c + 1;
      q.push(make_pair(make_pair(tmp_h - 1, tmp_w), tmp_c + 1));
    }
    if (tmp_h < H - 1 and stage[tmp_h + 1][tmp_w] == '.' and
        bar[tmp_h + 1][tmp_w] == -1) {
      bar[tmp_h + 1][tmp_w] = tmp_c + 1;
      q.push(make_pair(make_pair(tmp_h + 1, tmp_w), tmp_c + 1));
    }
    if (tmp_w > 0 and stage[tmp_h][tmp_w - 1] == '.' and
        bar[tmp_h][tmp_w - 1] == -1) {
      bar[tmp_h][tmp_w - 1] = tmp_c + 1;
      q.push(make_pair(make_pair(tmp_h, tmp_w - 1), tmp_c + 1));
    }
    if (tmp_w < W - 1 and stage[tmp_h][tmp_w + 1] == '.' and
        bar[tmp_h][tmp_w + 1] == -1) {
      bar[tmp_h][tmp_w + 1] = tmp_c + 1;
      q.push(make_pair(make_pair(tmp_h, tmp_w + 1), tmp_c + 1));
    }
  }
  cout << bar_c << endl;
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}
