#include <bits/stdc++.h>
using namespace std;
int64_t power(int64_t a, int64_t b) {
  int64_t r = 1;
  while (b) {
    if (b & 1) r = (r * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return r;
}
int64_t dp[20][20][20][20];
int64_t n, m;
string s[20];
void bfs(int64_t x, int64_t y, int64_t i, int64_t j, int64_t d) {
  if (i < 0 || j < 0 || i >= n || j >= m) return;
  if (s[i][j] == '#') return;
  if (dp[x][y][i][j] != -1 && dp[x][y][i][j] <= d) return;
  dp[x][y][i][j] = d;
  bfs(x, y, i - 1, j, d + 1);
  bfs(x, y, i + 1, j, d + 1);
  bfs(x, y, i, j - 1, d + 1);
  bfs(x, y, i, j + 1, d + 1);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int64_t ans = -1;
  cin >> n >> m;
  for (int64_t i = 0; i < n; i++) {
    cin >> s[i];
  }
  memset(dp, -1, sizeof(dp));
  for (int64_t i = 0; i < n; i++) {
    for (int64_t j = 0; j < m; j++) {
      bfs(i, j, i, j, 0);
    }
  }
  for (int64_t i = 0; i < n; i++) {
    for (int64_t j = 0; j < m; j++) {
      for (int64_t x = 0; x < n; x++) {
        for (int64_t y = 0; y < m; y++) {
          if (i != x && j != y) ans = max(ans, dp[i][j][x][y]);
        }
      }
    }
  }
  cout << ans << "\n";
}
