#include <bits/stdc++.h>
using namespace std;
int bfs(const vector<vector<bool>> &mapinfo, const pair<int, int> &start) {
  queue<pair<int, int>> pos;
  pos.push(start);
  vector<vector<int>> dist(mapinfo.size(),
                           vector<int>(mapinfo[0].size(), INT_MAX));
  dist[start.first][start.second] = 0;
  int dx[4] = {-1, 1, 0, 0};
  int dy[4] = {0, 0, -1, 1};
  int max_dist = 0;
  while (!pos.empty()) {
    auto from = pos.front();
    pos.pop();
    for (int i = 0; i < 4; i++) {
      auto to = make_pair(from.first + dy[i], from.second + dx[i]);
      if (to.first < 0 || to.first >= mapinfo.size() || to.second < 0 ||
          to.second >= mapinfo[0].size())
        continue;
      if (dist[to.first][to.second] != INT_MAX ||
          mapinfo[to.first][to.second] == false)
        continue;
      pos.push(to);
      max_dist = dist[to.first][to.second] = dist[from.first][from.second] + 1;
    }
  }
  return max_dist;
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<bool>> mapinfo(H, vector<bool>(W, false));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char s;
      cin >> s;
      if (s == '.') mapinfo[i][j] = true;
    }
  }
  int max = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      auto start = make_pair(i, j);
      max = std::max(max, bfs(mapinfo, start));
    }
  }
  cout << max << endl;
}
