#include <bits/stdc++.h>
using namespace std;
int a[22][22];
vector<pair<int, int> > d;
int id[22][22];
int main() {
  int n, m, i, s, j, k, p, t, r;
  cin >> n >> m;
  char x;
  memset(a, 0, sizeof(a));
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= m; ++j) {
      cin >> x;
      if (x == '.') a[i][j] = 1;
    }
  }
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= m; ++j) {
      if (!a[i][j]) continue;
      if (((!a[i - 1][j]) or (!a[i + 1][j])) and
              ((!a[i][j - 1]) or (!a[i][j + 1])) or
          ((!a[i - 1][j - 1]) and (!a[i + 1][j - 1])) and
              ((!a[i + 1][j - 1]) or (!a[i + 1][j + 1]))) {
        id[i][j] = d.size();
        d.push_back(make_pair(i, j));
        a[i][j] = 3;
        k = i + 1;
        while (a[k][j]) {
          a[k][j] = max(a[k][j], 2);
          k++;
        }
        k = i - 1;
        while (a[k][j]) {
          a[k][j] = max(a[k][j], 2);
          k--;
        }
        p = j + 1;
        while (a[i][p]) {
          a[i][p] = max(a[i][p], 2);
          p++;
        }
        p = j - 1;
        while (a[i][p]) {
          a[i][p] = max(a[i][p], 2);
          p--;
        }
      }
    }
  }
  int qm = d.size();
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= m; ++j) {
      if (a[i][j] == 2) {
        if ((a[i - 1][j] >= 2 or a[i + 1][j] >= 2) and
            (a[i][j - 1] >= 2 or a[i][j + 1] >= 2)) {
          a[i][j] = 4;
          id[i][j] = d.size();
          d.push_back(make_pair(i, j));
        }
      }
    }
  }
  int qq = d.size();
  int dis[qq][qq];
  memset(dis, 0, sizeof(dis));
  for (r = 0; r < qq; ++r) {
    i = d[r].first;
    j = d[r].second;
    k = i + 1;
    while (a[k][j] == 2) k++;
    if (k <= n and a[k][j] > 2) dis[r][id[k][j]] = k - i;
    k = i - 1;
    while (a[k][j] == 2) k--;
    if (k and a[k][j] > 2) dis[r][id[k][j]] = i - k;
    p = j + 1;
    while (a[i][p] == 2) p++;
    if (p <= m and a[i][p] > 2) dis[r][id[i][p]] = p - j;
    p = j - 1;
    while (a[i][p] == 2) p--;
    if (p and a[i][p] > 2) dis[r][id[i][p]] = j - p;
  }
  for (k = 0; k < qq; ++k)
    for (i = 0; i < qq; ++i)
      for (j = 0; j < qq; ++j)
        if (i != j and dis[i][k] and dis[k][j] and
            (dis[i][j] == 0 or (dis[i][j] > dis[i][k] + dis[k][j])))
          dis[i][j] = dis[i][k] + dis[k][j];
  int ans = 0;
  for (i = 0; i < qm; ++i)
    for (j = 0; j < qm; ++j) ans = max(ans, dis[i][j]);
  cout << ans;
  return 0;
}
