#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> steps(20, vector<int>(20, -1));
int H, W, ans = 0;
void setStep(vector<vector<bool>> G, int h, int w, int step) {
  steps.at(h).at(w) = step;
  if (h > 0) {
    if ((steps.at(h - 1).at(w) == -1 || step + 1 < steps.at(h - 1).at(w)) &&
        G.at(h - 1).at(w))
      setStep(G, h - 1, w, step + 1);
  }
  if (w < W - 1) {
    if ((steps.at(h).at(w + 1) == -1 || step + 1 < steps.at(h).at(w + 1)) &&
        G.at(h).at(w + 1))
      setStep(G, h, w + 1, step + 1);
  }
  if (h < H - 1) {
    if ((steps.at(h + 1).at(w) == -1 || step + 1 < steps.at(h + 1).at(w)) &&
        G.at(h + 1).at(w))
      setStep(G, h + 1, w, step + 1);
  }
  if (w > 0) {
    if ((steps.at(h).at(w - 1) == -1 || step + 1 < steps.at(h).at(w - 1)) &&
        G.at(h).at(w - 1))
      setStep(G, h, w - 1, step + 1);
  }
}
int findMaxStep() {
  int maxStep = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      maxStep = max(maxStep, steps.at(i).at(j));
      steps.at(i).at(j) = -1;
    }
  }
  return maxStep;
}
int main() {
  cin >> H >> W;
  vector<vector<bool>> G(H, vector<bool>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char g;
      cin >> g;
      if (g == '.') {
        G.at(i).at(j) = 1;
      } else if (g == '#') {
        G.at(i).at(j) = 0;
      }
    }
  }
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      if (!G.at(h).at(w)) continue;
      setStep(G, h, w, 0);
      int maxStep = findMaxStep();
      ans = max(maxStep, ans);
    }
  }
  cout << ans << endl;
}
