#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) { return x == 0 ? 1 : log10(x) + 1; }
signed main() {
  ll H, W;
  cin >> H >> W;
  string S[H][W];
  ll mapMap[H][W];
  ll mapMap2[H][W];
  P start = {0, 0};
  for (ll i = 0; i < (ll)(H); ++i) {
    string s;
    cin >> s;
    for (ll j = 0; j < (ll)(W); ++j) {
      char c = s[j];
      if (start.first == 0 && start.second == 0 && c == '.') {
        start = {i, j};
      }
      S[i][j] = c;
      mapMap[i][j] = 0;
      mapMap2[i][j] = 0;
    }
  }
  queue<pair<P, ll>> q;
  q.push({start, 0});
  ll max = 0;
  P maxP = start;
  while (!q.empty()) {
    pair<P, ll> qq = q.front();
    P p = qq.first;
    ll before = qq.second;
    q.pop();
    if (p.first < 0 || H <= p.first) {
      continue;
    }
    if (p.second < 0 || W <= p.second) {
      continue;
    }
    if (mapMap[p.first][p.second] == 1) {
      continue;
    }
    if (S[p.first][p.second] == "#") {
      continue;
    } else {
      mapMap[p.first][p.second] = 1;
      if (max < before + 1) {
        max = before + 1;
        maxP = {p.first, p.second};
      }
      q.push({{p.first + 1, p.second}, before + 1});
      q.push({{p.first - 1, p.second}, before + 1});
      q.push({{p.first, p.second + 1}, before + 1});
      q.push({{p.first, p.second - 1}, before + 1});
    }
  }
  queue<pair<P, ll>> q2;
  q2.push({maxP, 0});
  ll max2 = 0;
  while (!q2.empty()) {
    pair<P, ll> qq2 = q2.front();
    P p2 = qq2.first;
    ll before2 = qq2.second;
    q2.pop();
    if (p2.first < 0 || H <= p2.first) {
      continue;
    }
    if (p2.second < 0 || W <= p2.second) {
      continue;
    }
    if (mapMap2[p2.first][p2.second] == 1) {
      continue;
    }
    if (S[p2.first][p2.second] == "#") {
      continue;
    } else {
      mapMap2[p2.first][p2.second] = 1;
      if (max2 < before2 + 1) {
        max2 = before2 + 1;
      }
      q2.push({{p2.first + 1, p2.second}, before2 + 1});
      q2.push({{p2.first - 1, p2.second}, before2 + 1});
      q2.push({{p2.first, p2.second + 1}, before2 + 1});
      q2.push({{p2.first, p2.second - 1}, before2 + 1});
    }
  }
  cout << (max2 - 1) << endl;
  return 0;
}
