#include <bits/stdc++.h>
using namespace std;
const int N = 22;
char g[N][N];
uint32_t dp[N][N];
bool vis[N][N];
void dfs(int x, int y, uint32_t k = 0) {
  if (vis[x][y] or g[x][y] != '.') return;
  vis[x][y] = 1;
  dp[x][y] = min(dp[x][y], k);
  dfs(x + 1, y, k + 1);
  dfs(x - 1, y, k + 1);
  dfs(x, y + 1, k + 1);
  dfs(x, y - 1, k + 1);
  vis[x][y] = 0;
}
int main() {
  int n, m;
  uint32_t ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> g[i] + 1;
  for (int x = 1; x <= n; ++x)
    for (int y = 1; y <= m; ++y)
      if (g[x][y] == '.') {
        memset(dp, -1, sizeof(dp));
        dfs(x, y);
        for (int i = 1; i <= n; ++i)
          for (int j = 1; j <= m; ++j)
            if (g[i][j] == '.') ans = max(ans, dp[i][j]);
      }
  cout << ans;
  return 0;
}
