#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()



int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int H, W; cin >> H >> W;
  constexpr int INF = 1e9;
  vector<vector<int>> g(H * W, vector<int>(H * W, INF));
  rep(i, H * W) g[i][i] = 0;
  vector<string> G(H);
  rep(i, H) cin >> G[i];
  rep(i, H) rep(j, W) {
    if (i + 1 < H and G[i][j] == '.' and G[i + 1][j] == '.') {
      g[i * W + j][i * W + j + W] = 1;
      g[i * W + j + W][i * W + j] = 1;
    }
    if (j + 1 < W and G[i][j] == '.' and G[i][j + 1] == '.') {
      g[i * W + j][i * W + j + 1] = 1;
      g[i * W + j + 1][i * W + j] = 1;
    }
  }
  rep(k, H*W) rep(i, H*W) rep(j, H*W) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
  int ans = 0;
  rep(i, H*W) rep(j, H*W) if (g[i][j] != INF) ans = max(ans, g[i][j]);
  cout << ans << endl;
}