#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  int sx = -1, sy = -1;
  char c[h + 1][w + 1];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> c[i + 1][j + 1];
      if (sx == -1) {
        if (c[i + 1][j + 1] == '.') {
          sx = i + 1;
          sy = j + 1;
        }
      }
    }
  }
  std::multimap<int, std::pair<int, int>, std::greater<int>> maxdist;
  {
    std::queue<std::pair<int, int>> q;
    q.push(std::make_pair(sx, sy));
    std::vector<std::vector<int>> d;
    d = std::vector<std::vector<int>>(h + 1, std::vector<int>(w + 1, -1));
    d[sx][sy] = 0;
    while (!q.empty()) {
      std::pair<int, int> p = q.front();
      q.pop();
      for (int i = -1; i <= 1; i++) {
        for (int j = -1; j <= 1; j++) {
          if (std::abs(i + j) % 2 == 0) continue;
          int dx = p.first + i;
          int dy = p.second + j;
          if (1 <= dx && dx <= h && 1 <= dy && dy <= w && c[dx][dy] == '.' &&
              d[dx][dy] == -1) {
            q.push(std::make_pair(dx, dy));
            d[dx][dy] = d[p.first][p.second] + 1;
            maxdist.emplace(d[dx][dy], std::make_pair(dx, dy));
          }
        }
      }
    }
  }
  int maxd = maxdist.begin()->first;
  auto ret = maxdist.equal_range(maxd);
  int ans = 0;
  for (auto itr = ret.first; itr != ret.second; itr++) {
    int sx = itr->second.first;
    int sy = itr->second.second;
    std::queue<std::pair<int, int>> q;
    q.push(std::make_pair(sx, sy));
    std::vector<std::vector<int>> d;
    d = std::vector<std::vector<int>>(h + 1, std::vector<int>(w + 1, -1));
    d[sx][sy] = 0;
    int tmpmax = 0;
    while (!q.empty()) {
      std::pair<int, int> p = q.front();
      q.pop();
      for (int i = -1; i <= 1; i++) {
        for (int j = -1; j <= 1; j++) {
          if (std::abs(i + j) % 2 == 0) continue;
          int dx = p.first + i;
          int dy = p.second + j;
          if (1 <= dx && dx <= h && 1 <= dy && dy <= w && c[dx][dy] == '.' &&
              d[dx][dy] == -1) {
            q.push(std::make_pair(dx, dy));
            d[dx][dy] = d[p.first][p.second] + 1;
            if (tmpmax < d[dx][dy]) tmpmax = d[dx][dy];
          }
        }
      }
    }
    if (ans < tmpmax) ans = tmpmax;
  }
  cout << ans << endl;
}
