#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;
  vector<vector<long long>> block(h, vector<long long>(w));
  long long c = 0;
  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);
      if (block[i][j] == 0) c++;
    }
  }
  42;
  vector<vector<long long>> g(h * w);
  for (long long i = (long long)(0); i < (long long)(h); ++i)
    for (long long j = (long long)(0); j < (long long)(w); ++j) {
      long long u = i * w + j;
      if (block[i][j]) continue;
      vector<long long> dd = {1, w};
      for (long long k = (long long)(0);
           k < (long long)(((long long)(dd).size())); ++k) {
        long long v = u + dd[k];
        if (0 <= v && v < h * w) {
          if (block[v / w][v % w]) continue;
          if (v % w == 0 && dd[k] == 1) continue;
          g[u].push_back(v);
          g[v].push_back(u);
        }
      }
    }
  42;
  long long ans = 1;
  long long n = h * w;
  for (long long i = (long long)(0); i < (long long)(h); ++i)
    for (long long j = (long long)(0); j < (long long)(w); ++j) {
      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;
        for (auto &&v : g[u]) {
          if (d[u] + 1 < d[v]) {
            d[v] = d[u] + 1;
            chmax(ans, d[v]);
            q.push(v);
          }
        }
      }
    }
  cout << ans << endl;
  return 0;
}
