#include <bits/stdc++.h>
using namespace std;
bool in_range(int a, int b) { return a >= 0 && a < b; }
int bfs(const vector<string> &T, int sx, int sy) {
  int H = T.size(), W = T[0].size();
  const int INF = 1e9;
  vector<vector<int>> D(H, vector<int>(W, INF));
  queue<pair<int, int>> Q;
  Q.emplace(sx, sy);
  D[sx][sy] = 0;
  int ret = 0;
  int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
  while (Q.size()) {
    int x, y;
    tie(x, y) = Q.front();
    Q.pop();
    int d = D[x][y];
    for (int i = 0; i < 4; ++i) {
      int x_ = x + dx[i], y_ = y + dy[i];
      if (!in_range(x_, H)) continue;
      if (!in_range(y_, W)) continue;
      if (T[x_][y_] != '.') continue;
      if (d + 1 < D[x_][y_]) {
        D[x_][y_] = d + 1;
        Q.emplace(x_, y_);
        ret = max(ret, d + 1);
      }
    }
  }
  return ret;
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> T(H);
  for (int i = 0; i < H; ++i) cin >> T[i];
  int ans = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      ans = max(ans, bfs(T, i, j));
    }
  }
  cout << ans << endl;
}
