#include <bits/stdc++.h>
using namespace std;
int H, W;
int Two2One(int x, int y) { return y * W + x; }
pair<int, int> One2Two(int pos) {
  int x = pos % W;
  int y = pos / W;
  return make_pair(x, y);
}
int BFS(vector<vector<bool>> &s, vector<vector<bool>> &passed,
        vector<pair<int, int>> &next, int distance) {
  vector<int> dx = {-1, 1, 0, 0};
  vector<int> dy = {0, 0, -1, 1};
  vector<pair<int, int>> candidates;
  for (auto &elem : next) {
    int xcur = elem.first;
    int ycur = elem.second;
    for (int i = 0; i < 4; i++) {
      int xs = xcur + dx[i];
      int ys = ycur + dy[i];
      if (xs < 0 || ys < 0 || xs >= W || ys >= H) continue;
      if (!s[ys][xs]) continue;
      if (passed[ys][xs]) continue;
      passed[ys][xs] = true;
      candidates.emplace_back(make_pair(xs, ys));
    }
  }
  if (candidates.empty()) return distance;
  return BFS(s, passed, candidates, distance + 1);
}
int main() {
  cin >> H >> W;
  vector<vector<bool>> S(H, vector<bool>(W, false));
  for (int i = 0; i < H; i++) {
    string temp;
    cin >> temp;
    for (int j = 0; j < W; j++) S[i][j] = (temp[j] == '.');
  }
  int maxDistance = 0;
  for (int s = 0; s < H * W; s++) {
    auto pos_s = One2Two(s);
    if (!S[pos_s.second][pos_s.first]) continue;
    vector<vector<bool>> passed(H, vector<bool>(W, false));
    vector<pair<int, int>> first = {make_pair(pos_s.first, pos_s.second)};
    int distance = BFS(S, passed, first, 0);
    maxDistance = max(maxDistance, distance);
  }
  cout << maxDistance;
  return 0;
}
