#include <bits/stdc++.h>
using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;
template <typename T>
bool chmin(T a, T &b) {
  return a < b ? b = a, true : false;
}
template <typename T>
bool chmax(T a, T &b) {
  return a > b ? b = a, true : false;
}
constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();
ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
  if (n == 1) return false;
  for (ll i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
const vll dy = {-1, 0, 1, 0}, dx = {0, 1, 0, -1};
void solve();
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::setprecision(15);
  solve();
}
void solve() {
  ll h, w;
  std::cin >> h >> w;
  vstr s(h);
  for (ll i = 0; i < h; i++) std::cin >> s[i];
  vvll dist(h, vll(w, -1));
  auto bfs = [&](ll y, ll x) -> void {
    dist.assign(h, vll(w, -1));
    dist[y][x] = 0;
    std::queue<pll> que;
    que.push({y, x});
    while (!que.empty()) {
      pll p = que.front();
      que.pop();
      ll cy = p.first, cx = p.second;
      for (ll i = 0; i < 4; i++) {
        ll ny = cy + dy[i], nx = cx + dx[i];
        if (0 <= ny && ny < h && 0 <= nx && nx < w && s[ny][nx] == '.' &&
            dist[ny][nx] == -1) {
          dist[ny][nx] = dist[cy][cx] + 1;
          que.push({ny, nx});
        }
      }
    }
  };
  for (ll i = 0; i < h; i++)
    for (ll j = 0; j < w; j++)
      if (s[i][j] == '.') {
        bfs(i, j);
        break;
      }
  pll p;
  ll max_dist = -1;
  for (ll i = 0; i < h; i++)
    for (ll j = 0; j < w; j++)
      if (chmax(dist[i][j], max_dist)) p = {i, j};
  bfs(p.first, p.second);
  for (ll i = 0; i < h; i++)
    for (ll j = 0; j < w; j++)
      if (chmax(dist[i][j], max_dist)) p = {i, j};
  std::cout << max_dist << '\n';
}
