#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
using pii = pair<ll, ll>;
constexpr ll inf = 1ll << 61;
constexpr ll mod = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
T add(const T &a, const T &b) {
  return (a + b) % mod;
}
ll n;
vvi g;
pii bfs(ll s) {
  vi d(n, -1);
  queue<ll> q;
  d[s] = 0;
  ll maxd = 0;
  ll pos = s;
  q.push(s);
  while (!q.empty()) {
    ll next = q.front();
    q.pop();
    for (ll i = 0, i_cond = (g[next].size()); i < i_cond; ++i) {
      ll c = g[next][i];
      if (d[c] == -1) {
        d[c] = d[next] + 1;
        if (chmax(maxd, d[c])) pos = c;
        q.push(c);
      }
    }
  }
  return pii(pos, maxd);
}
ll diameter() {
  pii a = bfs(0);
  return bfs(a.first).second;
}
ll h, w;
vector<ll> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
bool isin(ll x, ll y) {
  bool ans;
  if (0 <= x and x < h and 0 <= y and y < w)
    ans = true;
  else
    ans = false;
  return ans;
}
signed main() {
  cin >> h >> w;
  n = h * w;
  vs s(h);
  for (ll i = 0, i_cond = (h); i < i_cond; ++i) cin >> s[i];
  g.resize(n);
  for (ll i = 0, i_cond = (h); i < i_cond; ++i)
    for (ll j = 0, j_cond = (w); j < j_cond; ++j) {
      if (s[i][j] == '#') continue;
      for (ll k = 0, k_cond = (4); k < k_cond; ++k) {
        ll nx = i + dx[k], ny = j + dy[k];
        if (isin(nx, ny) and s[nx][ny] == '.')
          g[h * i + j].push_back(h * nx + ny);
      }
    }
  cout << diameter() << endl;
}
