#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
void min_root(vvc &meiro, vvll &cnt, int i, int j, int n) {
  if (n >= cnt.at(i).at(j)) return;
  cnt.at(i).at(j) = n;
  if (meiro.at(i - 1).at(j) == '.') min_root(meiro, cnt, i - 1, j, n + 1);
  if (meiro.at(i + 1).at(j) == '.') min_root(meiro, cnt, i + 1, j, n + 1);
  if (meiro.at(i).at(j - 1) == '.') min_root(meiro, cnt, i, j - 1, n + 1);
  if (meiro.at(i).at(j + 1) == '.') min_root(meiro, cnt, i, j + 1, n + 1);
  return;
}
int main() {
  int h, w;
  cin >> h >> w;
  vvc meiro(h + 2, vc(w + 2, '#'));
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) cin >> meiro.at(i).at(j);
  ll mn = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      vvll cnt(h + 2, vll(w + 2, 10000));
      min_root(meiro, cnt, i, j, 0);
      ll mx = 0;
      for (int ii = 1; ii <= h; ii++) {
        for (int jj = 1; jj <= w; jj++) {
          if (meiro.at(ii).at(jj) == '.' && cnt.at(ii).at(jj) > mx)
            mx = cnt.at(ii).at(jj);
        }
      }
      if (mn < mx) mn = mx;
    }
  }
  cout << mn << endl;
}
