#include <bits/stdc++.h>
using namespace std;
int dist(int i, int j, int k, int l, vector<string>& S,
         vector<vector<bool>> is_visited) {
  if (i == k and j == l) return 0;
  is_visited[i][j] = true;
  int H = S.size();
  int W = S[i].size();
  int d = 1e+3;
  vector<pair<int, int>> next = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  for (auto p : next) {
    int nx = i + p.first;
    int ny = j + p.second;
    if (0 <= nx and nx < H and 0 <= ny and ny < W and S[nx][ny] == '.' and
        !is_visited[nx][ny])
      d = min(d, dist(nx, ny, k, l, S, is_visited) + 1);
  }
  return d;
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < (int)(H); ++i) cin >> S[i];
  int ans = 0;
  for (int i = 0; i < (int)(H); ++i) {
    for (int j = 0; j < (int)(W); ++j) {
      for (int k = 0; k < (int)(H); ++k) {
        for (int l = 0; l < (int)(W); ++l) {
          if (S[i][j] == '.' and S[k][l] == '.') {
            vector<vector<bool>> is_visited(H, vector<bool>(W, false));
            ans = max(ans, dist(i, j, k, l, S, is_visited));
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
