#include <bits/stdc++.h>
using namespace std;
long long K = 1000000007;
int main() {
  int H, W;
  cin >> H >> W;
  int INF = 100;
  int V = H * W;
  vector<vector<int>> d(V, vector<int>(V, INF));
  vector<vector<char>> Ma(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> Ma[i][j];
    }
  }
  for (int i = 0; i < V; i++) {
    d[i][i] = 0;
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (Ma[i][j] == '.') {
        if (i > 0) {
          if (Ma[i - 1][j] == '.') {
            d[i * W + j][(i - 1) * W + j] == 1;
            d[(i - 1) * W + j][i * W + j] == 1;
          }
        }
        if (i < H - 1) {
          if (Ma[i + 1][j] == '.') {
            d[i * W + j][(i + 1) * W + j] = 1;
            d[(i + 1) * W + j][i * W + j] = 1;
          }
        }
        if (j > 0) {
          if (Ma[i][j - 1] == '.') {
            d[i * W + j][i * W + j - 1] = 1;
            d[i * W + j - 1][i * W + j] = 1;
          }
        }
        if (j < W - 1) {
          if (Ma[i][j + 1] == '.') {
            d[i * W + j][i * W + j + 1] = 1;
            d[i * W + j + 1][i * W + j] = 1;
          }
        }
      }
    }
  }
  for (int k = 0; k < V; k++) {
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < V; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int Max = 0;
  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      if (d[i][j] < 100) {
        Max = max(Max, d[i][j]);
      }
    }
  }
  cout << Max;
}
