#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;
int search(pair<int, int>& pos) {
  map<pair<int, int>, int> s;
  queue<pair<int, int>> q;
  s[pos] = 0;
  q.push(pos);
  int md = -1;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    int d = s[p];
    if (d > md) {
      md = d;
      pos = 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;
}
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;
  }
  int ans = 0, ans2 = 1;
  for (auto p = make_pair(x, y); ans < (ans2 = search(p)); ans = ans2)
    ;
  cout << ans << endl;
  return 0;
}
