#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long MAXN = 1e+2 + 7;
const long long MOD = 1e+9 + 7, INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
double EPS = 1e-9;
double PI = acos(-1);
vector<long long> adj[MAXN];
long long visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1},
    dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};
long long t, n, m, k;
long long i, j, min1 = -1;
string second[100];
long long d[100][100], par[100][100], mat[100][100];
void floydW() {
  for (i = 1; i <= n * m; i++)
    for (j = 1; j <= n * m; j++) {
      d[i][j] = 10000, par[i][j] = 0;
    }
  for (i = 1; i <= n * m; i++)
    for (j = 1; j <= n * m; j++) {
      if (i != j && mat[i][j])
        d[i][j] = mat[i][j], par[i][j] = j;
      else
        d[i][i] = 0, par[i][i] = i;
    }
  for (k = 1; k <= n * m; k++)
    for (i = 1; i <= n * m; i++)
      for (j = 1; j <= n * m; j++) {
        if (d[i][k] + d[k][j] < d[i][j])
          d[i][j] = d[i][k] + d[k][j], par[i][j] = par[i][k];
      }
  for (i = 1; i <= n * m; i++) {
    for (j = 1; j <= n * m; j++) {
      if (d[i][j] != 10000 && d[i][j] > min1) {
        min1 = d[i][j];
      }
    }
  }
  cout << min1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(10);
  ;
  long long h, w;
  cin >> h >> w;
  n = h;
  m = w;
  for (i = 1; i <= h; i++)
    for (j = 1; j <= w; j++) cin >> second[i][j];
  for (i = 1; i <= 9; i++)
    for (j = 1; j <= 9; j++) mat[i][j] = 0;
  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      if (second[i][j] == '.') {
        if (j - 1 >= 1 && i >= 1 && i <= h && j - 1 <= w &&
            second[i][j - 1] == '.')
          mat[(i - 1) * w + j][(i - 1) * w + (j - 1)] = 1;
        if (j + 1 >= 1 && i >= 1 && i <= h && j + 1 <= w &&
            second[i][j + 1] == '.')
          mat[(i - 1) * w + j][(i - 1) * w + (j + 1)] = 1;
        if (j >= 1 && i + 1 >= 1 && i + 1 <= h && j <= w &&
            second[i + 1][j] == '.')
          mat[(i - 1) * w + j][i * w + j] = 1;
        if (j >= 1 && i - 1 >= 1 && i - 1 <= h && j <= w &&
            second[i - 1][j] == '.')
          mat[(i - 1) * w + j][(i - 2) * w + j] = 1;
      }
    }
  }
  floydW();
}
