#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll H, W;
vector<string> S;
vector<ll> board(400);
inline bool isOK(ll i, ll j, ll cur) {
  if (!(0 <= i && i < W && 0 <= j && j < H)) {
    return false;
  }
  if (S[j][i] == '#') {
    return false;
  }
  if (board[j * W + i] <= cur) {
    return false;
  }
  return true;
}
ll srch(ll i, ll j, ll gi, ll gj, ll cur) {
  if (i == gi && j == gj) {
    return cur;
  }
  board[j * W + i] = cur;
  ll mn = 19190721;
  ll dS[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  for (ll t = 0; t < 4; t++) {
    ll ni = i + dS[t][0];
    ll nj = j + dS[t][1];
    if (isOK(ni, nj, cur + 1)) {
      ll tmp = srch(ni, nj, gi, gj, cur + 1);
      if (tmp >= 0) {
        mn = min(mn, tmp);
      }
    }
  }
  if (mn == 19190721) {
    return -1;
  }
  return mn;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string tmp;
    cin >> tmp;
    S.push_back(tmp);
  }
  ll mx = 0;
  for (ll si = 0; si < W; si++) {
    for (ll sj = 0; sj < H; sj++) {
      for (ll gi = 0; gi < W; gi++) {
        for (ll gj = 0; gj < H; gj++) {
          if (S[sj][si] == '.' && S[gj][gi] == '.') {
            fill(board.begin(), board.end(), 1000000);
            ll tmp = srch(si, sj, gi, gj, 0);
            mx = max(tmp, mx);
          }
        }
      }
    }
  }
  cout << mx << endl;
  return 0;
}
