#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
int H, W;
vector<string> S;
tuple<int, int, int> dfs(int x, int y) {
  map<pair<int, int>, int> s;
  queue<pair<int, int>> q;
  s[{x, y}] = 0;
  q.emplace(x, y);
  int md = -1;
  pair<int, int> mp;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    int d = s[p];
    if (d > md) {
      md = d;
      mp = p;
    }
    for (int i = 0; i < (4); i++) {
      int x = p.first + dx[i], y = p.second + dy[i];
      auto n = s.find({x, y});
      if (n != s.end() || x < 0 || x >= W || y < 0 || y >= H || S[y][x] != '.')
        continue;
      s[{x, y}] = d + 1;
      q.emplace(x, y);
    }
  }
  return {md, mp.first, mp.second};
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W;
  S.resize(H);
  for (int i = 0; i < (H); i++) cin >> S[i];
  int x, y;
  for (y = 0; y < H; y++) {
    x = S[y].find('.');
    if (x != string::npos) break;
  }
  auto p = dfs(x, y);
  cout << get<0>(dfs(get<1>(p), get<2>(p))) << endl;
  return 0;
}
