#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
ll bfs(vector<string> S, ll si, ll sj) {
  queue<pair<ll, ll>> Q;
  vector<vector<ll>> C(((ll)(S).size()), vector<ll>(((ll)(S[0]).size()), -1));
  ll pi, pj, di, dj;
  Q.push({si, sj});
  C[si][sj] = 0;
  while (!Q.empty()) {
    pair<ll, ll> p = Q.front();
    Q.pop();
    pi = p.first;
    pj = p.second;
    if (S[pi][pj] == '#') continue;
    vector<pair<ll, ll>> D = {
        {pi - 1, pj}, {pi, pj + 1}, {pi + 1, pj}, {pi, pj - 1}};
    for (auto(d) : D) {
      di = d.first;
      dj = d.second;
      if (C[di][dj] == -1 && S[di][dj] == '.') {
        C[di][dj] = C[pi][pj] + 1;
        Q.push({di, dj});
      }
    }
  }
  ll m = 0;
  for (auto(_c) : C) {
    for (auto(c) : _c) m = (((m) > (c)) ? (m) : (c));
  }
  return m;
}
int main() {
  ll H, W;
  cin >> H >> W;
  vector<string> S(H + 2);
  string s;
  for (ll(i) = (0), (i_len) = (W + 2); (i) < (i_len); ++(i)) S[0] += "#";
  for (ll(i) = (1), (i_len) = (H + 1); (i) < (i_len); ++(i)) {
    cin >> s;
    S[i] = '#' + s + '#';
  }
  for (ll(i) = (0), (i_len) = (W + 2); (i) < (i_len); ++(i)) S[H + 1] += "#";
  ll m = 0, c;
  for (ll(i) = (1), (i_len) = (H + 1); (i) < (i_len); ++(i)) {
    for (ll(j) = (1), (i_len) = (W + 1); (j) < (i_len); ++(j)) c = bfs(S, i, j);
    m = (((m) > (c)) ? (m) : (c));
  }
  cout << (m) << endl;
  return 0;
}
