#include <bits/stdc++.h>
using namespace std;
static const int INFTY = (1 << 21);
int n, color[10002], d[10002];
vector<pair<int, int> > adj[10002];
void dijkstra(int p) {
  priority_queue<pair<int, int> > PQ;
  d[p] = 0;
  color[p] = 1;
  PQ.push(make_pair(0, p));
  while (!PQ.empty()) {
    pair<int, int> f = PQ.top();
    PQ.pop();
    int u = f.second;
    color[u] = 2;
    if (d[u] < f.first * (-1)) continue;
    for (int j = 0; j < adj[u].size(); j++) {
      int v = adj[u][j].first;
      if (color[v] == 2) continue;
      if (d[v] > d[u] + adj[u][j].second) {
        d[v] = d[u] + adj[u][j].second;
        PQ.push(make_pair(d[v] * (-1), v));
        color[v] = 1;
      }
    }
  }
}
int main() {
  int h, w, p = -1, m = -1;
  cin >> h >> w;
  n = (h + 2) * (w + 2);
  char x[22 * 22 + 5], c;
  for (int i = 0; i < ((h + 2) * (w + 2)); ++i) {
    if (i % (w + 2) == 0 || i % (w + 2) == (w + 1) || i < w + 2 ||
        i >= (w + 2) * (h + 1))
      x[i] = '#';
    else {
      cin >> x[i];
    }
  }
  for (int i = 0; i < ((h + 2) * (w + 2)); ++i) {
    if (x[i] - '.' == 0) {
      if (x[i - 1] - '.' == 0) adj[i].push_back(make_pair(i - 1, 1));
      if (x[i + 1] - '.' == 0) adj[i].push_back(make_pair(i + 1, 1));
      if (x[i - (w + 2)] - '.' == 0)
        adj[i].push_back(make_pair(i - (w + 2), 1));
      if (x[i + (w + 2)] - '.' == 0)
        adj[i].push_back(make_pair(i + (w + 2), 1));
      if (p == -1) p = i;
    }
  }
  for (int i = 0; i < n; i++) {
    color[i] = 0;
    d[i] = INFTY;
  }
  dijkstra(p);
  for (int i = 0; i < (n); ++i) {
    if (d[i] != INFTY && m < d[i]) {
      p = i;
      m = d[i];
    }
  }
  for (int i = 0; i < n; i++) {
    color[i] = 0;
    d[i] = INFTY;
  }
  dijkstra(p);
  m = 0;
  for (int i = 0; i < (n); ++i) {
    if (d[i] != INFTY && m < d[i]) m = d[i];
  }
  cout << m << endl;
}
