#include <bits/stdc++.h>
using namespace std;
const int maxn = 30;
int n, m, px, py, ans, vis[maxn][maxn], lenth[maxn][maxn];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
char s[maxn][maxn];
void dfs(int x, int y, int num) {
  lenth[x][y] = min(lenth[x][y], num);
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && s[nx][ny] == '.' &&
        !vis[nx][ny]) {
      vis[nx][ny] = 1;
      dfs(nx, ny, num + 1);
      vis[nx][ny] = 0;
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = (1); i <= (n); ++i) scanf("%s", s[i] + 1);
  memset(lenth, 0x3f, sizeof(lenth));
  int mx = 0;
  dfs(1, 1, 0);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (lenth[i][j] != 0x3f3f3f3f && lenth[i][j] > mx) {
        mx = lenth[i][j];
        px = i;
        py = j;
      }
    }
  memset(lenth, 0x3f, sizeof(lenth));
  memset(vis, 0, sizeof(vis));
  dfs(px, py, 0);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (lenth[i][j] != 0x3f3f3f3f && lenth[i][j] > ans) {
        ans = lenth[i][j];
      }
    }
  cout << ans << endl;
  return 0;
}
