#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
vector<vector<int>> bfs(vector<vector<int>> &g, int h, int w, int sy, int sx) {
  assert(g[sy][sx] == 0);
  vector<vector<int>> ret(h, vector<int>(w, INF));
  priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>,
                 greater<pair<int, pair<int, int>>>>
      pque;
  map<pair<int, int>, bool> mp;
  pque.push({0, {sy, sx}});
  while (!pque.empty()) {
    auto cur = pque.top();
    pque.pop();
    if (mp[cur.second] == true) {
      continue;
    }
    ret[cur.second.first][cur.second.second] = cur.first;
    mp[cur.second] = true;
    int y = cur.second.first;
    int x = cur.second.second;
    if (y + 1 < h && g[y + 1][x] == 0) {
      pque.push({cur.first + 1, {y + 1, x}});
    }
    if (y - 1 >= 0 && g[y - 1][x] == 0) {
      pque.push({cur.first + 1, {y - 1, x}});
    }
    if (x + 1 < w && g[y][x + 1] == 0) {
      pque.push({cur.first + 1, {y, x + 1}});
    }
    if (x - 1 >= 0 && g[y][x - 1] == 0) {
      pque.push({cur.first + 1, {y, x - 1}});
    }
  }
  return ret;
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> g(h, vector<int>(w, 0));
  int sy, sx;
  for (long long i = (long long)(0); i < (long long)(h); ++i)
    for (long long j = (long long)(0); j < (long long)(w); ++j) {
      char s;
      cin >> s;
      if (s == '.') {
        g[i][j] = 0;
        sy = i;
        sx = j;
      } else {
        g[i][j] = 1;
      }
    }
  auto cost = bfs(g, h, w, sy, sx);
  for (long long i = (long long)(0); i < (long long)(h); ++i) {
    for (long long j = (long long)(0); j < (long long)(w); ++j) {
      cerr << cost[i][j] << " ";
    }
    cerr << endl;
  }
  int mcost = -1;
  for (long long i = (long long)(0); i < (long long)(h); ++i)
    for (long long j = (long long)(0); j < (long long)(w); ++j) {
      if (cost[i][j] == INF) continue;
      if (mcost < cost[i][j]) {
        sy = i;
        sx = j;
        mcost = cost[i][j];
      }
    }
  cost = bfs(g, h, w, sy, sx);
  mcost = -1;
  for (long long i = (long long)(0); i < (long long)(h); ++i)
    for (long long j = (long long)(0); j < (long long)(w); ++j) {
      if (cost[i][j] == INF) continue;
      if (mcost < cost[i][j]) {
        sy = i;
        sx = j;
        mcost = cost[i][j];
      }
    }
  cout << mcost << endl;
  return 0;
}
