#include <bits/stdc++.h>
using namespace std;
int I[20][20];
int D[400][400];
int main() {
  ios::sync_with_stdio(false);
  int H, W;
  string S[20];
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  int N = 1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') {
        I[i][j] = N++;
      }
    }
  }
  int INF = 100000;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      D[i][j] = INF;
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') {
        int k = I[i][j];
        D[k][k] = 0;
        if (i >= 0) {
          int l = I[i - 1][j];
          D[k][l] = D[l][k] = 1;
        }
        if (j >= 0) {
          int l = I[i][j - 1];
          D[k][l] = D[l][k] = 1;
        }
        if (i < H - 1) {
          int l = I[i + 1][j];
          D[k][l] = D[l][k] = 1;
        }
        if (j < W - 1) {
          int l = I[i][j + 1];
          D[k][l] = D[l][k] = 1;
        }
      }
    }
  }
  for (int k = 1; k < N; k++) {
    for (int i = 1; i < N; i++) {
      for (int j = 1; j < N; j++) {
        D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
      }
    }
  }
  int ret = 0;
  for (int i = 1; i < N; i++) {
    for (int j = 1; j < N; j++) {
      if (D[i][j] < INF) {
        ret = max(ret, D[i][j]);
      }
    }
  }
  cout << ret << endl;
}
