#include <bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
signed main() {
  int h, w;
  cin >> h >> w;
  vector<bool> maze(h * w, false);
  for (int i = 0; i < h; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < w; ++j)
      if (s[j] == '.') maze[i * w + j] = true;
  }
  int res = 0;
  for (int src = 0; src < h * w; ++src) {
    if (!maze[src]) continue;
    queue<pi> que;
    que.push(pi(src, 0));
    vector<bool> vis(h * w, false);
    vector<int> cost(h * w, 1e7);
    while (!que.empty()) {
      pi q = que.front();
      que.pop();
      int& cur = q.first;
      vis[cur] = true;
      cost[cur] = min(cost[cur], q.second);
      if (cur - w >= 0 && maze[cur - w] && !vis[cur - w])
        que.push(pi(cur - w, q.second + 1));
      if (cur + w < h * w && maze[cur + w] && !vis[cur + w])
        que.push(pi(cur + w, q.second + 1));
      if (cur % w - 1 >= 0 && maze[cur - 1] && !vis[cur - 1])
        que.push(pi(cur - 1, q.second + 1));
      if (cur % w + 1 < w && maze[cur + 1] && !vis[cur + 1])
        que.push(pi(cur + 1, q.second + 1));
    }
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (maze[i * w + j]) res = max(res, cost[i * w + j]);
      }
    }
  }
  cout << res;
}
