#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long cnt[200004];
int mat[405][405];
bool thonk[1004];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int rows, cols;
  cin >> rows >> cols;
  int g[rows][cols];
  for (int r = 0; r < rows; r++) {
    string s;
    cin >> s;
    for (int c = 0; c < cols; c++) {
      g[r][c] = (s[c] == '.');
      thonk[r * cols + c] = g[r][c];
    }
  }
  int n = rows * cols;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) mat[i][j] = 5002313;
  }
  for (int r = 0; r < rows; r++) {
    for (int c = 0; c < cols - 1; c++) {
      if (g[r][c] && g[r][c + 1]) {
        int a = r * cols + c;
        int b = r * cols + c + 1;
        mat[a][b] = 1;
        mat[b][a] = 1;
      }
    }
  }
  for (int r = 0; r < rows - 1; r++) {
    for (int c = 0; c < cols; c++) {
      if (g[r][c] && g[r + 1][c]) {
        int a = r * cols + c;
        int b = (r + 1) * cols + c;
        mat[a][b] = 1;
        mat[b][a] = 1;
      }
    }
  }
  for (int k = 0; k < n; k++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (thonk[i] && thonk[j]) ans = max(ans, mat[i][j]);
    }
  }
  cout << ans;
}
