#include <iostream>
#include <queue>
#include <tuple>
#include <vector>

using namespace std;

int H, W, ans;
bool S[20][20];
pair<int, int> D[4]{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

void dfs(int sh, int sw) {
  queue<tuple<int, int, int>> q;
  vector<vector<int>> p(H, vector<int>(W,H*W));
  q.emplace(sh, sw, 0);
  p[sh][sw] = 0;
  int maxt{};
  while (!q.empty()) {
    auto [h, w, t] = q.front();
    maxt = t;
    q.pop();
    for (auto [dh, dw] : D) {
      int nh = h + dh, nw = w + dw;
      if (nh >= 0 && nh < H && nw >= 0 && nw < W && S[nh][nw] &&
          p[nh][nw] > t + 1) {
        q.emplace(h + dh, w + dw, t + 1);
        p[nh][nw] = t + 1;
      }
    }
  }
  ans = max(maxt, ans);
}

int main() {
  cin >> H >> W;
  string r;
  vector<pair<int, int>> v;
  for (int i = 0; i != H; ++i) {
    cin >> r;
    for (int j = 0; j != W; ++j) {
      S[i][j] = r[j] == '.';
      if (S[i][j]) v.emplace_back(i, j);
    }
  }
  for (auto [sh, sw] : v) dfs(sh, sw);
  cout << ans << endl;
}
