#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}
ll vi[20][20];
ll vii[20][20];
int main() {
  for (ll i = 0; i < 20; i++) {
    for (ll j = 0; j < 20; j++) {
      vi[i][j] = 0;
      vii[i][j] = 0;
    }
  }
  ll h, w;
  cin >> h >> w;
  vector<string> v;
  for (ll i = 0; i < h; i++) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  ll sx, sy;
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      if (v[i][j] == '.') {
        sx = j;
        sy = i;
        break;
      }
    }
  }
  ll m = 0;
  ll mx, my;
  queue<pair<pair<ll, ll>, ll>> q;
  set<pair<ll, ll>> visited;
  ll d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
  q.push(make_pair(make_pair(sx, sy), 0));
  while (!q.empty()) {
    ll x = q.front().first.first;
    ll y = q.front().first.second;
    ll cost = q.front().second;
    vi[y][x] = 1;
    if (cost > m) {
      mx = x;
      my = y;
      m = cost;
    }
    q.pop();
    for (ll i = 0; i < 4; i++) {
      ll nx = x + d[i][0];
      ll ny = y + d[i][1];
      if (0 <= nx and nx < w and 0 <= ny and ny < h and v[ny][nx] == '.' and
          vi[ny][nx] == 0) {
        q.push(make_pair(make_pair(nx, ny), cost + 1));
      }
    }
  }
  m = 0;
  q.push(make_pair(make_pair(mx, my), 0));
  set<pair<ll, ll>> vis;
  while (!q.empty()) {
    ll x = q.front().first.first;
    ll y = q.front().first.second;
    ll cost = q.front().second;
    vii[y][x] = 1;
    vis.insert(make_pair(x, y));
    if (cost > m) {
      mx = x;
      my = y;
      m = cost;
    }
    q.pop();
    for (ll i = 0; i < 4; i++) {
      ll nx = x + d[i][0];
      ll ny = y + d[i][1];
      if (0 <= nx and nx < w and 0 <= ny and ny < h and v[ny][nx] == '.' and
          vii[ny][nx] == 0) {
        q.push(make_pair(make_pair(nx, ny), cost + 1));
      }
    }
  }
  std::cout << m << std::endl;
  return 0;
}
