#include <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, -1, 0, 1};
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> m(h, vector<char>(w));
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) cin >> m.at(i).at(j);
  int ans = 0;
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) {
      queue<int> q;
      q.push(i);
      q.push(j);
      vector<vector<int>> dist(h, vector<int>(w, -1));
      dist.at(i).at(j) = 0;
      while (!q.empty()) {
        int ci = q.front();
        q.pop();
        int cj = q.front();
        q.pop();
        for (int k = 0; k < (4); k++) {
          int ni = ci + di.at(k);
          int nj = cj + dj.at(k);
          if (ni < 0 || ni > h - 1 || nj < 0 || nj > w - 1) continue;
          if (m.at(ni).at(nj) == '.' && dist.at(ni).at(nj) == -1) {
            q.push(ni);
            q.push(nj);
            dist.at(ni).at(nj) = dist.at(ci).at(cj) + 1;
          }
        }
      }
      for (int di = 0; di < (h); di++)
        for (int dj = 0; dj < (w); dj++) ans = max(ans, dist.at(di).at(dj));
    }
  cout << ans << endl;
}
