#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using iii = pair<int, ii>;
using ll = long long;
int mdis(vector<string> mt, int i, int j) {
  int n = (int)(mt.size());
  int m = (int)(mt[0].size());
  queue<iii> q;
  q.push({0, {i, j}});
  int ans = 0;
  while (not q.empty()) {
    auto [d, _pos] = q.front();
    q.pop();
    auto [i, j] = _pos;
    ans = max(ans, d);
    mt[i][j] = '#';
    if (i > 0 and mt[i - 1][j] != '#') q.push({d + 1, {i - 1, j}});
    if (i < n - 1 and mt[i + 1][j] != '#') q.push({d + 1, {i + 1, j}});
    if (j < m - 1 and mt[i][j + 1] != '#') q.push({d + 1, {i, j + 1}});
    if (j > 0 and mt[i][j - 1] != '#') q.push({d + 1, {i, j - 1}});
  }
  return ans;
}
int32_t main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<string> mt(n);
  for (auto &s : mt) cin >> s;
  int ans = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) ans = max(ans, mdis(mt, i, j));
  cout << ans << endl;
}
