#include <bits/stdc++.h>
using namespace std;
int h, w, dp[405][405];
int dr[4] = {-1, 0, 1, 0};
int dc[4] = {0, 1, 0, -1};
char grid[405][405];
vector<int> nodes;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> h >> w;
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      dp[i][j] = 1e9;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> grid[i][j];
      if (grid[i][j] == '.') {
        nodes.push_back(i * w + j);
        dp[i * w + j][i * w + j] = 0;
      }
    }
  }
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      if (i == j && grid[i][j] == '.') {
        dp[i][j] = 0;
      } else {
        dp[i][j] = 1e9;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (grid[i][j] == '.') {
        for (int k = 0; k < 4; k++) {
          int r = i + dr[k], c = j + dc[k];
          if (r >= 0 && r < h && c >= 0 && c < w && grid[r][c] == '.') {
            dp[i * w + j][r * w + c] = 1;
          }
        }
      }
    }
  }
  for (int k = 0; k < nodes.size(); k++) {
    for (int i = 0; i < nodes.size(); i++) {
      for (int j = 0; j < nodes.size(); j++) {
        dp[nodes[i]][nodes[j]] =
            min(dp[nodes[i]][nodes[j]],
                dp[nodes[i]][nodes[k]] + dp[nodes[k]][nodes[j]]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < nodes.size(); i++) {
    for (int j = 0; j < nodes.size(); j++) {
      ans = max(ans, dp[nodes[i]][nodes[j]]);
    }
  }
  cout << ans << '\n';
  return 0;
}
