#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
const int INF = 1 << 10;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) cin >> s.at(i).at(j);
  int cur = 0;
  int n = 0;
  vector<vector<int>> temp(h, vector<int>(w, -1));
  for (int i = 0; i < (h); ++i) {
    for (int j = 0; j < (w); ++j) {
      if (s.at(i).at(j) == '.') {
        temp.at(i).at(j) = cur++;
        n++;
      }
    }
  }
  vector<vector<int>> G(n, vector<int>());
  for (int i = 0; i < (h); ++i) {
    for (int j = 0; j < (w); ++j) {
      int ij = temp.at(i).at(j);
      if (ij == -1) {
        continue;
      }
      for (int k = 0; k < (4); ++k) {
        int nx = j + dx[k];
        int ny = i + dy[k];
        if (nx < 0 || nx >= w || ny < 0 || ny >= h) {
          continue;
        }
        int z = temp.at(ny).at(nx);
        if (z == -1) {
          continue;
        }
        G.at(ij).push_back(z);
      }
    }
  }
  vector<vector<int>> c(n, vector<int>(n, INF));
  for (int i = 0; i < (n); ++i) {
    for (int x : G.at(i)) {
      c.at(i).at(x) = 1;
    }
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        c.at(i).at(j) = min(c.at(i).at(j), c.at(i).at(k) + c.at(k).at(j));
      }
    }
  }
  int res = 0;
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (n); ++j) {
      res = max(res, c.at(i).at(j));
    }
  }
  cout << res << endl;
  return 0;
}
