#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
const long long MOD = 1000000007;
char S[40][40];
ll H, W;
bool visited[40][40];
ll bfs(ll si, ll sj, ll gi, ll gj) {
  for (int(i) = 0; (i) < (H); ++(i))
    for (int(j) = 0; (j) < (W); ++(j)) visited[i][j] = false;
  queue<pll> que;
  que.push(pll(si * W + sj, 0));
  ll ret = 0;
  while (!que.empty()) {
    ll i = que.front().first / W;
    ll j = que.front().first % W;
    ll d = que.front().second;
    que.pop();
    if (visited[i][j]) continue;
    visited[i][j] = true;
    if (i == gi && j == gj) return d;
    if (S[i][j] == '#') continue;
    if (i >= 0) que.push(pll((i - 1) * W + j, d + 1));
    if (i < H - 1) que.push(pll((i + 1) * W + j, d + 1));
    if (j >= 0) que.push(pll(i * W + j - 1, d + 1));
    if (j < W - 1) que.push(pll(i * W + j + 1, d + 1));
  }
  return ret;
}
signed main() {
  cin >> H >> W;
  string str;
  for (int(i) = 0; (i) < (H); ++(i)) {
    cin >> str;
    for (int(j) = 0; (j) < (W); ++(j)) {
      S[i][j] = str[j];
    }
  }
  ll ans = 0;
  for (int(i) = 0; (i) < (H); ++(i)) {
    for (int(j) = 0; (j) < (W); ++(j)) {
      if (S[i][j] == '#') continue;
      for (int(k) = 0; (k) < (H); ++(k)) {
        for (int(l) = 0; (l) < (W); ++(l)) {
          if (S[k][l] == '#') continue;
          ans = max(ans, bfs(i, j, k, l));
        }
      }
    }
  }
  cout << (ans) << "\n";
}
