#include <bits/stdc++.h>
using namespace std;
int h, w;
string s[20];
vector<pair<int, int>> p;
map<pair<pair<int, int>, pair<int, int>>, int> d;
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> s[i];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++)
      if (s[i][j] == '.') p.push_back(make_pair(i, j));
  }
  for (int i = 0; i < p.size(); i++)
    for (int j = 0; j < p.size(); j++)
      if (d.find(make_pair(p[i], p[j])) == d.end())
        if (abs(p[i].first - p[j].first) + abs(p[i].second - p[j].second) > 1)
          d[make_pair(p[i], p[j])] = 10000000;
        else
          d[make_pair(p[i], p[j])] =
              abs(p[i].first - p[j].first) + abs(p[i].second - p[j].second);
  for (int i = 0; i < p.size(); i++) {
    for (int j = 0; j < p.size(); j++) {
      for (int k = 0; k < p.size(); k++) {
        d[make_pair(p[j], p[k])] =
            min(d[make_pair(p[j], p[k])],
                d[make_pair(p[j], p[i])] + d[make_pair(p[i], p[k])]);
      }
    }
  }
  int res = 0;
  for (int i = 0; i < p.size(); i++)
    for (int j = 0; j < p.size(); j++) res = max(res, d[make_pair(p[i], p[j])]);
  cout << res << endl;
}
