#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  for (string& i : v) cin >> i;
  int val = h * w;
  vector<vector<int> > dp(val, vector<int>(val, 0x3f3f3f3f));
  for (int i = 0; i < h * w; i++) dp[i][i] = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (v[i][j] == '#') continue;
      int arx[] = {-1, 1, 0, 0};
      int ary[] = {0, 0, -1, 1};
      for (int k = 0; k < 4; k++) {
        int nx = i + arx[k], ny = j + ary[k];
        if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
        if (v[nx][ny] == '#')
          dp[i * h + j][nx * h + ny] = 0x3f3f3f3f;
        else
          dp[i * h + j][nx * h + ny] = 1;
      }
    }
  }
  for (int k = 0; k < val; k++) {
    for (int i = 0; i < val; i++) {
      for (int j = 0; j < val; j++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  int mx = 0;
  for (int i = 0; i < val; i++)
    for (int j = 0; j < val; j++)
      if (dp[i][j] != 0x3f3f3f3f) mx = max(mx, dp[i][j]);
  cout << mx << "\n";
  return 0;
}
