#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  int ex[4] = {0, 0, 1, -1};
  int ey[4] = {1, -1, 0, 0};
  map<pair<int, int>, char> s;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[make_pair(i, j)];
    }
  }
  auto bfs = [&](int x, int y) -> map<pair<int, int>, int> {
    map<pair<int, int>, int> dis;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        dis[make_pair(i, j)] = -1;
      }
    }
    deque<pair<int, int>> q;
    q.push_back(make_pair(x, y));
    dis[make_pair(x, y)] = 0;
    while (!q.empty()) {
      pair<int, int> p = q.front();
      q.pop_front();
      for (int i = 0; i < 4; i++) {
        int H = p.first + ey[i];
        int W = p.second + ex[i];
        if (dis[make_pair(H, W)] != -1) continue;
        if (0 <= H && H < h && 0 <= W && W < w) {
          if (s[make_pair(H, W)] == '.') {
            dis[make_pair(H, W)] = dis[p] + 1;
            q.push_back(make_pair(H, W));
          }
        }
      }
    }
    return dis;
  };
  int M = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      auto G = bfs(i, j);
      for (int ii = 0; ii < h; ii++) {
        for (int jj = 0; jj < w; jj++) {
          M = max(M, G[make_pair(ii, jj)]);
        }
      }
    }
  }
  cout << M << "\n";
}
