#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int h, w;
vector<vector<int>> d;
void make_way(int i, int j, int s, int t) {
  d[i * h + j][s * h + t] = 1;
  d[s * h + t][i * h + j] = 1;
}
int main() {
  cin >> h >> w;
  const int INF = 1 << 20;
  for (long long i = 0; i < (long long)(h * w); ++i) {
    vector<int> tmp(h * w, INF);
    d.push_back(tmp);
  }
  vector<string> s(h);
  for (long long i = 0; i < (long long)(h); ++i) {
    cin >> s[i];
  }
  for (long long i = 0; i < (long long)(h * w); ++i) d[i][i] = 0;
  for (long long i = 0; i < (long long)(h); ++i) {
    for (long long j = 0; j < (long long)(w); ++j) {
      if (s[i][j] == '#') continue;
      if (i != 0 && s[i - 1][j] == '.') make_way(i, j, i - 1, j);
      if (j != 0 && s[i][j - 1] == '.') make_way(i, j, i, j - 1);
      if (i != h - 1 && s[i + 1][j] == '.') make_way(i, j, i + 1, j);
      if (j != w - 1 && s[i][j + 1] == '.') make_way(i, j, i, j + 1);
    }
  }
  for (long long k = 0; k < (long long)(h * w); ++k) {
    for (long long i = 0; i < (long long)(h * w); ++i) {
      for (long long j = 0; j < (long long)(h * w); ++j) {
        chmin(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int ans = 0;
  for (long long i = 0; i < (long long)(h * w); ++i) {
    for (long long j = 0; j < (long long)(h * w); ++j) {
      if (d[i][j] != INF) chmax(ans, d[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
