#include <bits/stdc++.h>
using namespace std;
int n, m;
string t[1111];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool visit[111][111];
int che(int x, int y, int gx, int gy) {
  if (t[y][x] != '.') return 1e7;
  if (x == gx && y == gy) {
    return 0;
  }
  if (visit[y][x]) return 1e7;
  visit[y][x] = 1;
  int ret = 1e7;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    if (nx < 0 || ny < 0 || nx >= m || ny >= n) continue;
    ret = min(ret, che(nx, ny, gx, gy) + 1);
  }
  visit[y][x] = 0;
  return ret;
}
signed main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> t[i];
  int ans = 0;
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < m; k++)
        for (int l = 0; l < n; l++) {
          int ret = che(i, j, k, l);
          if (ret != 1e7) ans = max(ans, ret);
        }
  cout << ans << endl;
  return 0;
}
