#include <bits/stdc++.h>
using namespace std;
string maze[30];
int a[500][500], Next[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> maze[i];
  memset(a, 0x3f, sizeof a);
  for (int i = 1; i <= n * m; i++) a[i][i] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (maze[i][j] == '.')
        for (int k = 0; k < 4; k++) {
          int tx = i + Next[k][0], ty = j + Next[k][1];
          if (tx < 0 || ty < 0 || tx >= n || ty >= m) continue;
          if (maze[tx][ty] == '.') a[i * n + j + 1][tx * n + ty + 1] = 1;
        }
    }
  }
  for (int k = 1; k <= n * m; k++)
    for (int i = 1; i <= n * m; i++)
      for (int j = 1; j <= n * m; j++)
        a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
  int ans = 0;
  for (int i = 1; i <= n * m; i++)
    for (int j = 1; j <= n * m; j++)
      if (a[i][j] != 1061109567) ans = max(ans, a[i][j]);
  cout << ans << endl;
  return 0;
}
