#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int> > g1(h * w, vector<int>(h * w, INF));
  vector<vector<int> > g2(h, vector<int>(w));
  int g1_len = (int)g1.size();
  for (int i = 0; i < (g1_len); ++i) {
    g1[i][i] = 0;
  }
  for (int i = 0; i < (h); ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < (w); ++j) {
      if (s[j] == '.') g2[i][j] = 1;
    }
  }
  for (int i = 0; i < (h); ++i) {
    for (int j = 0; j < (w); ++j) {
      if (g2[i][j] == 1) {
        if (i > 0 and g2[i - 1][j] == 1) {
          g1[i * h + j][(i - 1) * h + j] = 1;
          g1[(i - 1) * h + j][i * h + j] = 1;
        }
        if (i < h - 1 and g2[i + 1][j] == 1) {
          g1[i * h + j][(i + 1) * h + j] = 1;
          g1[(i + 1) * h + j][i * h + j] = 1;
        }
        if (j > 0 and g2[i][j - 1] == 1) {
          g1[i * h + j][i * h + (j - 1)] = 1;
          g1[i * h + (j - 1)][i * h + j] = 1;
        }
        if (j < w - 1 and g2[i][j + 1] == 1) {
          g1[i * h + j][i * h + (j + 1)] = 1;
          g1[i * h + (j + 1)][i * h + j] = 1;
        }
      }
    }
  }
  for (int k = 0; k < (g1_len); ++k) {
    for (int i = 0; i < (g1_len); ++i) {
      for (int j = 0; j < (g1_len); ++j) {
        g1[i][j] = min(g1[i][j], g1[i][k] + g1[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < (g1_len); ++i) {
    for (int j = 0; j < (g1_len); ++j) {
      if (g1[i][j] < INF) {
        ans = max(ans, g1[i][j]);
      }
    }
  }
  cout << ans << endl;
}
