#include <bits/stdc++.h>
const int maxn = 20 + 3, maxv = maxn * maxn;
const int dxy[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int h, w;
char s[maxn][maxn];
int d[maxn][maxn], ans;
bool vis[maxn][maxn];
void bfs(int u, int v) {
  std::queue<std::tuple<int, int>> q;
  memset(vis, 0, sizeof(vis));
  d[u][v] = 0;
  vis[u][v] = true;
  q.emplace(u, v);
  while (!q.empty()) {
    auto [x, y] = q.front();
    q.pop();
    for (auto &&[dx, dy] : dxy) {
      if (x + dx < 0 || x + dx >= h || y + dy < 0 || y + dy >= w ||
          vis[x + dx][y + dy] || s[x + dx][y + dy] == '#') {
        continue;
      }
      d[x + dx][y + dy] = d[x][y] + 1;
      vis[x + dx][y + dy] = true;
      q.emplace(x + dx, y + dy);
    }
  }
}
void update() {
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (vis[i][j]) {
        ans = std::max(ans, d[i][j]);
      }
    }
  }
}
int main() {
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; ++i) {
    scanf("%s", s[i]);
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '.') {
        bfs(i, j);
        update();
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
