#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  int l = v.size();
  for (int i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
const int inf = 1e9 + 10;
const long long int INF = 1e18 + 10;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 10;
void solve() {
  int h, w;
  cin >> h >> w;
  string g[30];
  int m[500][500] = {0};
  int r = w;
  for (int i = 0; i < h; i++) cin >> g[i];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (j > 0 && g[i][j - 1] != '#') {
        m[i * r + j][i * r + j - 1] = 1;
      }
      if (i + 1 < h && g[i + 1][j] != '#') {
        m[i * r + j][i * r + j + r] = 1;
      }
      if (j + 1 < w && g[i][j + 1] != '#') {
        m[i * r + j][i * r + j + 1] = 1;
      }
      if (i > 0 && g[i - 1][j] != '#') {
        m[i * r + j][i * r + j - r] = 1;
      }
    }
  }
  int dp[500][500] = {0};
  memset(dp, inf, sizeof(dp));
  ;
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      dp[i][j] = m[i][j];
    }
  }
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      if (!dp[i][j]) dp[i][j] = inf;
    }
  }
  for (int i = 0; i < 500; i++) dp[i][i] = 0;
  for (int k = 0; k < h * w; k++) {
    for (int i = 0; i < h * w; i++) {
      for (int j = 0; j < h * w; j++) {
        dp[i][j] = min({dp[i][k] + dp[k][j], dp[i][j]});
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      if (dp[i][j] != inf) ans = max({ans, dp[i][j]});
    }
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
