#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  int H, W;
  cin >> H >> W;
  string field[H];
  for (int h = 0; h < H; h++) {
    cin >> field[h];
    cout << field[h] << endl;
  }
  int N = H * W;
  int dest[N][N];
  for (int hf = 0; hf < H; hf++) {
    for (int wf = 0; wf < W; wf++) {
      for (int ht = 0; ht < H; ht++) {
        for (int wt = 0; wt < W; wt++) {
          int d = abs(hf - ht) + abs(wf - wt);
          int nt = ht * W + wt;
          int nf = hf * W + wf;
          if (field[ht][wt] == '#' or field[hf][wf] == '#') {
            dest[nf][nt] = -1;
            dest[nt][nf] = -1;
          } else if (d == 1) {
            dest[nf][nt] = 1;
            dest[nt][nf] = 1;
          } else if (d == 0) {
            dest[nf][nt] = 0;
          } else {
            dest[nf][nt] = -1;
            dest[nt][nf] = -1;
          }
        }
      }
    }
  }
  for (int nt = 0; nt < N; nt++) {
    for (int nf = 0; nf < N; nf++) {
      for (int n = 0; n < N; n++) {
        if (dest[nf][n] >= 0 and dest[n][nt] >= 0) {
          if (dest[nf][nt] == -1) {
            dest[nf][nt] = dest[nf][n] + dest[n][nt];
          } else {
            dest[nf][nt] = min(dest[nf][nt], dest[nf][n] + dest[n][nt]);
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      ans = max(dest[i][j], ans);
    }
  }
  cout << ans << endl;
}
