#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, step, num = 0, ans = 0;
  cin >> h >> w;
  char a[h][w];
  queue<pair<int, int>> q;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> a[i][j];
      if (a[i][j] == '.') {
        q.push(make_pair(i, j));
      }
    }
  }
  while (q.size()) {
    auto ij = q.front();
    q.pop();
    int i = ij.first, j = ij.second;
    queue<pair<pair<int, int>, int>> qq;
    qq.push(make_pair(make_pair(i, j), 0));
    step = 0;
    int b[h][w];
    for (int k = 0; k < h; ++k) {
      for (int l = 0; l < w; ++l) {
        b[k][l] = 0;
      }
    }
    while (qq.size()) {
      auto iijj = qq.front();
      qq.pop();
      int ii = iijj.first.first, jj = iijj.first.second;
      step = iijj.second;
      if (ii > 0) {
        if (a[ii - 1][jj] == '.') {
          if (b[ii - 1][jj] == 0) {
            step++;
            b[ii - 1][jj] = step;
            qq.push(make_pair(make_pair(ii - 1, jj), step));
          } else {
            if (b[ii - 1][jj] > step + 1) {
              step++;
              b[ii - 1][jj] = step;
              qq.push(make_pair(make_pair(ii - 1, jj), step));
            }
          }
        }
      }
      if (ii < h - 1) {
        if (a[ii + 1][jj] == '.') {
          if (b[ii + 1][jj] == 0) {
            step++;
            b[ii + 1][jj] = step;
            qq.push(make_pair(make_pair(ii + 1, jj), step));
          } else {
            if (b[ii + 1][jj] > step + 1) {
              step++;
              b[ii + 1][jj] = step;
              qq.push(make_pair(make_pair(ii + 1, jj), step));
            }
          }
        }
      }
      if (j > 0) {
        if (a[ii][jj - 1] == '.') {
          if (b[ii][jj - 1] == 0) {
            step++;
            b[ii][jj - 1] = step;
            qq.push(make_pair(make_pair(ii, jj - 1), step));
          } else {
            if (b[ii][jj - 1] > step + 1) {
              step++;
              b[ii][jj - 1] = step;
              qq.push(make_pair(make_pair(ii, jj - 1), step));
            }
          }
        }
      }
      if (j < w - 1) {
        if (a[ii][jj + 1] == '.') {
          if (b[ii][jj + 1] == 0) {
            step++;
            b[ii][jj + 1] = step;
            qq.push(make_pair(make_pair(ii, jj + 1), step));
          } else {
            if (b[ii][jj + 1] > step + 1) {
              step++;
              b[ii][jj + 1] = step;
              qq.push(make_pair(make_pair(ii, jj + 1), step));
            }
          }
        }
      }
      ans = max(ans, step);
    }
  }
  cout << ans - 1 << '\n';
}
