#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> vs(H);
  vector<pair<int, int> > road;
  for (int i = 0; i < H; i++) {
    cin >> vs.at(i);
    for (int j = 0; j < W; j++) {
      if (vs.at(i).at(j) == '.') {
        road.push_back(make_pair(i, j));
      }
    }
  }
  vector<int> vx = {1, -1, 0, 0};
  vector<int> vy = {0, 0, 1, -1};
  int ans = 0;
  for (int i = 0; i < road.size(); i++) {
    queue<pair<int, int> > que;
    vector<vector<int> > t(H, vector<int>(W, 0));
    vector<vector<bool> > flag(H, vector<bool>(W, false));
    int ma = 0;
    que.push(road.at(i));
    while (!que.empty()) {
      int y, x;
      tie(y, x) = que.front();
      que.pop();
      for (int j = 0; j < 4; j++) {
        int ny = y + vy.at(j);
        int nx = x + vx.at(j);
        if (ny == -1) {
          continue;
        }
        if (nx == -1) {
          continue;
        }
        if (ny == H) {
          continue;
        }
        if (nx == W) {
          continue;
        }
        if ((vs.at(ny).at(nx) == '.') && (!flag.at(ny).at(nx))) {
          flag.at(ny).at(nx) = true;
          que.push(make_pair(ny, nx));
          t.at(ny).at(nx) = t.at(y).at(x) + 1;
          if (ma < t.at(ny).at(nx)) {
            ma = t.at(ny).at(nx);
          }
        }
      }
    }
    if (ans < ma) {
      ans = ma;
    }
  }
  cout << ans << endl;
  return 0;
}
