#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
template <class T>
inline void chmax(T &a, const T &b) {
  if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
  if ((a) > (b)) (a) = (b);
}
template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast {
  Fast() {
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
signed main() {
  long long h, w;
  cin >> h >> w;
  long long n = h * w;
  vector<vector<long long>> block(h, vector<long long>(w));
  for (long long i = (long long)(0); i < (long long)(h); ++i) {
    string s;
    cin >> s;
    for (long long j = (long long)(0); j < (long long)(w); ++j) {
      block[i][j] = (s[j] == '.' ? 0 : 1);
    }
  }
  42;
  vector<vector<long long>> g(n);
  long long di[] = {1, -1, 0, 0};
  long long dj[] = {0, 0, 1, -1};
  for (long long i = (long long)(0); i < (long long)(h); ++i)
    for (long long j = (long long)(0); j < (long long)(w); ++j) {
      if (block[i][j]) continue;
      long long u = i * w + j;
      for (long long k = (long long)(0); k < (long long)(4); ++k) {
        long long ni = i + di[k];
        long long nj = j + dj[k];
        long long v = ni * w + nj;
        if (((0) <= (ni) && (ni) < (h)) && ((0) <= (nj) && (nj) < (w))) {
          g[u].push_back(v);
        }
      }
    }
  42;
  long long ans = 1;
  for (long long i = (long long)(0); i < (long long)(h); ++i)
    for (long long j = (long long)(0); j < (long long)(w); ++j) {
      if (block[i][j]) continue;
      long long u = i * w + j;
      queue<long long> q;
      vector<long long> used(n);
      q.push(u);
      vector<long long> d(n, INF);
      d[u] = 0;
      while (!q.empty()) {
        auto u = q.front();
        q.pop();
        if (used[u]) continue;
        used[u] = 1;
        chmax(ans, d[u]);
        for (auto &&v : g[u]) {
          if (d[u] + 1 < d[v]) {
            d[v] = d[u] + 1;
            q.push(v);
          }
        }
      }
    }
  assert(ans < INF);
  cout << ans << endl;
  return 0;
}
