#include <bits/stdc++.h>
using namespace std;
const long long INF = 100000000L;
int get_v(int i, int j, int H, int W) {
  if (i < 0 || i >= H) return -1;
  if (j < 0 || j >= W) return -1;
  return i + H * j;
}
int main() {
  int H, W, N;
  cin >> H >> W;
  N = H * W;
  vector<string> strs;
  for (int i = 0; i < H; ++i) {
    string s;
    cin >> s;
    strs.push_back(s);
  }
  vector<vector<long long>> ds(N, vector<long long>(N, INF));
  for (int i = 0; i < H; ++i) {
    for (int j = 0; i < W; ++j) {
      int n = get_v(i, j, H, W);
      int n1 = get_v(i + 1, j, H, W);
      if (n1 >= 0 && strs[i + 1][j] == '.') {
        ds[n][n1] = 1;
      }
      int n2 = get_v(i, j + 1, H, W);
      if (n2 >= 0 && strs[i][j + 1] == '.') {
        ds[n][n2] = 1;
      }
      int n3 = get_v(i - 1, j, H, W);
      if (n3 >= 0 && strs[i - 1][j] == '.') {
        ds[n][n3] = 1;
      }
      int n4 = get_v(i, j - 1, H, W);
      if (n4 >= 0 && strs[i][j - 1] == '.') {
        ds[n][n4] = 1;
      }
    }
  }
  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j]);
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      long long d = ds[i][j];
      if (d < INF && d > ans) {
        ans = d;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
