#include <bits/stdc++.h>
using ll = long long;
constexpr ll INF = std::numeric_limits<ll>::max() >> 2;
using P = std::pair<int, int>;
using St = std::pair<ll, P>;
int H, W;
char S[30][30];
ll dist[30][30];
const int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
ll bfs(int si, int sj) {
  for (int i = (0); i < (30); ++i)
    for (int j = (0); j < (30); ++j) dist[i][j] = INF;
  dist[si][sj] = 0;
  std::queue<St> que;
  que.push(St(0, P(si, sj)));
  while (!que.empty()) {
    St st = que.front();
    que.pop();
    ll d = st.first;
    int i = st.second.first, j = st.second.second;
    dist[i][j] = d;
    for (int dir = (0); dir < (4); ++dir) {
      int ni = i + dx[dir], nj = j + dy[dir];
      if (ni >= 0 && ni < H && nj >= 0 && nj < W && S[ni][nj] != '#' &&
          dist[ni][nj] == INF)
        que.push(St(d + 1, P(ni, nj)));
    }
  }
  return 0;
}
int main() {
  scanf("%d%d", &H, &W);
  for (int i = (0); i < (H); ++i) scanf("%s", S[i]);
  ll ans = 0;
  for (int si = (0); si < (H); ++si)
    for (int sj = (0); sj < (W); ++sj)
      if (S[si][sj] != '#') {
        bfs(si, sj);
        for (int gi = (0); gi < (H); ++gi)
          for (int gj = (0); gj < (W); ++gj)
            if (S[gi][gj] != '#' && dist[gi][gj] != INF)
              ans = std::max(ans, dist[gi][gj]);
      }
  printf("%lld\n", ans);
  return 0;
}
