#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
void pPRINT(std::ostream& ost) {}
template <class T, class... U>
void pPRINT(std::ostream& ost, const T t, const U... u) {
  ost << t << " ";
  pPRINT(ost, u...);
}
template <class... T>
void PRINT(const T... t) {
  pPRINT(std::cout, t...);
}
template <class... T>
void PRINTl(const T... t) {
  pPRINT(std::cout, t...);
  std::cout << "\n";
}
template <class T>
void PRINTa(const T* const t, const ll size) {
  for (int i = 0; i < size; i++) PRINT(t[i]);
  PRINTl();
}
template <class T>
void PRINTal(const T* const t, const ll size) {
  for (int i = 0; i < size; i++) PRINTl(i, ":", t[i]);
}
template <class T>
void DEBUGARR(const T* const t, const ll size) {}
template <class T>
void DEBUGARRL(const T* const t, const ll size) {}
void init() {
  ;
  cin.tie(0);
  ios::sync_with_stdio(false);
}
ll dfs(vector<vector<ll>>& tree, ll parent, ll now, ll depth) {
  ll d = depth;
  for (auto i : tree[now]) {
    if (i == parent) continue;
    d = max(d, dfs(tree, now, i, depth + 1));
  }
  return d;
}
void solve();
int main(int argc, char* argv[]) {
  ;
  init();
  solve();
  return 0;
}
char s[20][20];
ll v[20][20];
void check(ll h, ll w, stack<pair<ll, ll>>& stk) {
  ll val = 1;
  ll sign[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
  while (stk.size() > 0) {
    stack<pair<ll, ll>> nextstk;
    while (stk.size() > 0) {
      auto p = stk.top();
      stk.pop();
      ll i = p.first;
      ll j = p.second;
      v[i][j] = val;
      ;
      for (int t = 0; t < 4; t++) {
        ll ni = i + sign[t][0];
        ll nj = j + sign[t][1];
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        ;
        if (s[ni][nj] == '.' && v[ni][nj] == 0) {
          nextstk.push(pair<ll, ll>(ni, nj));
        }
      }
    }
    swap(stk, nextstk);
    val++;
  }
}
void solve() {
  ;
  ll h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  memset(v[0], 0, sizeof(ll) * 20 * 20);
  stack<pair<ll, ll>> stk;
  bool findtop = false;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        ;
        stk.push(pair<ll, ll>(i, j));
        findtop = true;
        break;
      }
    }
    if (findtop) break;
  }
  check(h, w, stk);
  ll maxval = 0;
  pair<ll, ll> maxpair(0, 0);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (v[i][j] > maxval) {
        maxval = v[i][j];
        maxpair = pair<ll, ll>(i, j);
      }
    }
  }
  stk.push(maxpair);
  memset(v[0], 0, sizeof(ll) * 20 * 20);
  check(h, w, stk);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (v[i][j] > maxval) {
        maxval = v[i][j];
      }
    }
  }
  PRINT(maxval - 1);
  return;
}
