#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = (ll)1e18;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr ll dx[4] = {1LL, 0LL, -1LL, 0LL};
constexpr ll dy[4] = {0LL, 1LL, 0LL, -1LL};
constexpr ll dx8[8] = {1LL, 0LL, -1LL, 0LL, 1LL, 1LL, -1LL, -1LL};
constexpr ll dy8[8] = {0LL, 1LL, 0LL, -1LL, 1LL, -1LL, 1LL, -1LL};
void p() { std::cout << '\n'; }
template <typename Head, typename... Tail>
void p(Head head, Tail... tail) {
  std::cout << head << (sizeof...(tail) ? " " : "");
  p(tail...);
}
template <typename T>
inline void pv(vector<T>& v) {
  for (ll i = 0, N = v.size(); i < N; i++)
    std::cout << v[i] << " \n"[i == N - 1];
}
template <typename T>
inline T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
inline bool chmax(T& a, T b) {
  return a < b && (a = b, true);
}
template <typename T>
inline bool chmin(T& a, T b) {
  return a > b && (a = b, true);
}
template <typename T>
inline void uniq(vector<T>& v) {
  v.erase(unique(v.begin(), v.end()), v.end());
}
const ll H_MAX = 20;
const ll W_MAX = 20;
ll H, W;
vector<string> S;
void solve() {
  scanf("%lld%lld", &H, &W);
  S.assign(H, "");
  for (ll i = 0, i_length = (H); i < i_length; ++i) {
    cin >> S[i];
  }
  ll ans = 0;
  ll a = 0, b = 0;
  for (ll i = 0, i_length = (H); i < i_length; ++i)
    for (ll j = 0, j_length = (W); j < j_length; ++j) {
      if (S[i][j] == '.') {
        a = i;
        b = j;
      }
    }
  vector<vector<ll>> dis(H, vector<ll>(W, 10000));
  queue<pair<ll, ll>> que;
  que.push({a, b});
  dis[a][b] = 0;
  while (!que.empty()) {
    pair<ll, ll> v = que.front();
    que.pop();
    for (ll k = 0, k_length = (4); k < k_length; ++k) {
      ll nx = dx[k] + v.first;
      ll ny = dy[k] + v.second;
      if (nx <= -1 || ny <= -1 || nx >= H || ny >= W) continue;
      if (S[nx][ny] == '#') continue;
      if (chmin(dis[nx][ny], dis[v.first][v.second] + 1)) {
        que.push({nx, ny});
      }
    }
  }
  {};
  vector<vector<ll>> dis2(H, vector<ll>(W, 10000));
  ll sx = 0, sy = 0;
  ll maxval = 0;
  for (ll i = 0, i_length = (H); i < i_length; ++i)
    for (ll j = 0, j_length = (W); j < j_length; ++j) {
      if (dis[i][j] == 10000) continue;
      if (chmax(maxval, dis[i][j])) {
        sx = i;
        sy = j;
      }
    }
  {};
  dis2[sx][sy] = 0;
  que.push({sx, sy});
  while (!que.empty()) {
    pair<ll, ll> v = que.front();
    que.pop();
    for (ll k = 0, k_length = (4); k < k_length; ++k) {
      ll nx = dx[k] + v.first;
      ll ny = dy[k] + v.second;
      if (nx <= -1 || ny <= -1 || nx >= H || ny >= W) continue;
      if (S[nx][ny] == '#') continue;
      if (chmin(dis2[nx][ny], dis2[v.first][v.second] + 1)) {
        que.push({nx, ny});
      }
    }
  }
  {};
  maxval = 0;
  for (ll i = 0, i_length = (H); i < i_length; ++i)
    for (ll j = 0, j_length = (W); j < j_length; ++j) {
      if (dis[i][j] == 10000) continue;
      chmax(maxval, dis2[i][j]);
    }
  printf("%lld\n", maxval);
}
signed main() {
  solve();
  return 0;
}
