#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> map(h);
  vector<vector<int>> itta(h, vector<int>(w));
  vector<vector<int>> hou(4, vector<int>(2));
  vector<vector<int>> mi(0, vector<int>(4));
  hou = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
  for (int i = 0; i < (h); ++i) cin >> map.at(i);
  int x0, y0, x1, y1;
  int cou = 0;
  int max = 0;
  int zx = 0;
  int zy = 0;
  for (int i = 0; i < h * w - 1; i++) {
    for (int j = i + 1; j < h * w; j++) {
      y0 = i / w;
      x0 = i % w;
      y1 = j / w;
      x1 = j % w;
      if (!(map.at(y0).at(x0) == '#' || map.at(y1).at(x1) == '#'))
        mi.push_back({x0, y0, x1, y1});
    }
  }
  for (int i = mi.size() - 1; i >= 0; i--) {
    y0 = mi.at(i).at(1);
    x0 = mi.at(i).at(0);
    y1 = mi.at(i).at(3);
    x1 = mi.at(i).at(2);
    if (itta.at(y1).at(x1) != 0) {
      for (int i0 = 0; i0 < (h); ++i0) {
        for (int j0 = 0; j0 < (w); ++j0) {
          itta.at(i0).at(j0) = 0;
        }
      }
      continue;
    }
    for (int i0 = 0; i0 < (h); ++i0) {
      for (int j0 = 0; j0 < (w); ++j0) {
        itta.at(i0).at(j0) = 0;
      }
    }
    itta.at(y0).at(x0) = 1;
    cou = 1;
    int f = 0;
    while (itta.at(y1).at(x1) == 0) {
      f = 0;
      cou++;
      for (int i0 = 0; i0 < (h); ++i0) {
        for (int j0 = 0; j0 < (w); ++j0) {
          if (itta.at(i0).at(j0) == cou - 1) {
            for (int k = 0; k < (4); ++k) {
              zx = j0 + hou.at(k).at(0);
              zy = i0 + hou.at(k).at(1);
              if (!(zx < 0 || zx >= w || zy < 0 || zy >= h)) {
                if (map.at(zy).at(zx) == '.' && itta.at(zy).at(zx) == 0) {
                  itta.at(zy).at(zx) = cou;
                  f = 1;
                }
              }
            }
          }
        }
      }
      if (f == 0) break;
    }
    if (max < cou && f == 1) max = cou;
  }
  cout << max - 1 << endl;
}
