#include <bits/stdc++.h>
using namespace std;
template <typename T>
void cins(vector<T>& arr) {
  for (T& e : arr) cin >> e;
}
pair<int, int> dir4[4] = {
    {0, 1},
    {1, 0},
    {-1, 0},
    {0, -1},
};
int main(void) {
  int row, col;
  cin >> row >> col;
  vector<vector<char>> map(row + 2, vector<char>(col + 2));
  for (int i = 1; i <= row; i++) {
    string str;
    cin >> str;
    for (int j = 1; j <= col; j++) {
      map[i][j] = (str[j - 1] == '.');
    }
  }
  int vs = (row + 2) * (col + 2);
  vector<vector<int>> graph(vs, vector<int>(vs, 100000));
  for (int i = 1; i <= row; i++) {
    for (int j = 1; j <= col; j++) {
      int src = i * (col + 2) + j;
      if (!map[i][j]) continue;
      for (auto d : dir4) {
        pair<int, int> np = make_pair(i + d.first, j + d.second);
        if (!map[np.first][np.second]) continue;
        int dst = np.first * (col + 2) + np.second;
        graph[src][dst] = 1;
      }
    }
  }
  for (int k = 0; k < vs; k++) {
    for (int i = 0; i < vs; i++) {
      for (int j = 0; j < vs; j++) {
        int nnew = graph[i][k] + graph[k][j];
        if (nnew >= 100000) continue;
        graph[i][j] = min(graph[i][j], nnew);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < vs; i++) {
    for (int j = 0; j < vs; j++) {
      if (graph[i][j] == 100000) continue;
      ans = max(ans, graph[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
