#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e6 + 5;
char mp[21][21];
int dir[4][2] = {1, 0, 0, -1, -1, 0, 0, 1};
int d[500][500];
int h, w;
int id(int x, int y) { return (x - 1) * w + y; }
void add(int x, int y) {
  for (int i = (int)0; i <= (int)3; i++) {
    int dx = x + dir[i][0], dy = y + dir[i][1];
    if (dx < 1 || dx > h || dy < 1 || dy > w) continue;
    if (mp[dx][dy] == '.')
      d[id(x, y)][id(dx, dy)] = d[id(dx, dy)][id(x, y)] = 1;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> h >> w;
  int n = h * w;
  for (int i = (int)1; i <= (int)h * w; i++)
    for (int j = (int)1; j <= (int)h * w; j++)
      if (i == j)
        d[i][j] = 0;
      else
        d[i][j] = 100;
  for (int i = (int)1; i <= (int)h; i++)
    for (int j = (int)1; j <= (int)w; j++) cin >> mp[i][j];
  for (int i = (int)1; i <= (int)h; i++)
    for (int j = (int)1; j <= (int)w; j++)
      if (mp[i][j] == '.') add(i, j);
  for (int k = (int)1; k <= (int)n; k++)
    for (int i = (int)1; i <= (int)n; i++)
      for (int j = (int)1; j <= (int)n; j++)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  int ans = 0;
  for (int i = (int)1; i <= (int)n; i++)
    for (int j = (int)1; j <= (int)n; j++)
      if (d[i][j] != 100) ans = max(ans, d[i][j]);
  cout << ans << endl;
}
