#include <bits/stdc++.h>
using namespace std;
int n, m, mx, s, t, w, k, l, p, x, y, xx, yy, b[4000], c[4000], f[21][21];
int d[4][2] = {{-1, 0}, {}};
char a[21][21];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  d[0][0] = -1, d[0][1] = 0;
  d[1][0] = 1, d[1][1] = 0;
  d[2][0] = 0, d[2][1] = -1;
  d[3][0] = 0, d[3][1] = 1;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      memset(f, 63, sizeof(f));
      p = f[1][1];
      t = 1, w = 1, b[1] = i, c[1] = j;
      f[i][j] = 0;
      while (t <= w) {
        x = b[t];
        y = c[t];
        for (int k = 0; k < 4; k++) {
          xx = x + d[k][0];
          yy = y + d[k][1];
          if (xx >= 0 && xx < n && yy >= 0 && yy < m && a[xx][yy] == '.' &&
              f[x][y] + 1 < f[xx][yy]) {
            w++;
            b[w] = xx;
            c[w] = yy;
            f[xx][yy] = f[x][y] + 1;
          }
        }
        t++;
      }
      for (int k = 0; k < n; k++)
        for (int l = 0; l < m; l++)
          if (f[k][l] != p) mx = max(mx, f[k][l]);
    }
  cout << mx << endl;
  return 0;
}
