#include <bits/stdc++.h>
using namespace std;
int a[] = {1, -1, 0, 0};
int b[] = {0, 0, 1, -1};
int main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  int h, w, x, y, ans = 0;
  cin >> h >> w;
  int adjmat[h * w + 2][h * w + 2];
  char mat[h + 2][w + 2];
  memset(mat, '#', sizeof(mat));
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      cin >> mat[i][j];
    }
  }
  for (int i = 0; i < h * w + 2; i++) {
    for (int j = 0; j < h * w + 2; j++) adjmat[i][j] = 9999;
  }
  for (int i = 0; i <= h * w + 1; i++) adjmat[i][i] = 0;
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      for (int p = 0; p < 4; p++) {
        y = j + a[p];
        x = i + b[p];
        if (mat[x][y] == '.') adjmat[(i - 1) * w + j][(x - 1) * w + y] = 1;
      }
    }
  }
  for (int k = 1; k < h * w + 1; k++) {
    for (int i = 1; i < h * w + 1; i++) {
      for (int j = 1; j < h * w + 1; j++) {
        adjmat[i][j] = min(adjmat[i][j], adjmat[i][k] + adjmat[k][j]);
      }
    }
  }
  for (int i = 1; i < h * w + 1; i++) {
    for (int j = 1; j < h * w + 1; j++) {
      if (adjmat[i][j] != 9999) ans = max(ans, adjmat[i][j]);
    }
  }
  cout << ans;
}
