#include <bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll, ll>;
using PP = std::pair<P, ll>;
int h, w;
std::vector<std::vector<bool>> fie(22, std::vector<bool>(22, 1));
;
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
ll bfs(P sp) {
  ll ret = 0;
  std::vector<std::vector<bool>> used(fie);
  std::queue<PP> que;
  que.push(PP(sp, 0));
  while (!que.empty()) {
    P p;
    ll d;
    std::tie(p, d) = que.front();
    que.pop();
    used[p.first][p.second] = true;
    ret = std::max(ret, d);
    for (int i = 0; i < 4; i++) {
      ll nx = p.first + dx[i], ny = p.second + dy[i];
      if (!used[nx][ny]) que.push(PP(P(nx, ny), d + 1));
    }
  }
  return ret;
}
int main() {
  scanf("%d %d", &h, &w);
  for (int i = 0; i < h + 2; i++)
    for (int j = 0; j < w + 2; j++) fie[i][j] = 1;
  for (int i = 1; i < h + 1; i++) {
    char s[w + 1];
    scanf("%s", s);
    for (int j = 1; j < w + 1; j++) fie[i][j] = (s[j - 1] == '#');
  }
  ll ans = 0;
  for (int sx = 1; sx < h + 1; sx++)
    for (int sy = 1; sy < w + 1; sy++) {
      ans = std::max(ans, bfs(P(sx, sy)));
    }
  printf("%ld\n", ans);
  return 0;
}
