#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream& operator>>(istream& istr, vector<T>& vec) {
  for (T& x : vec) istr >> x;
  return istr;
}
template <typename T>
ostream& operator<<(ostream& ostr, vector<T>& vec) {
  if (!vec.empty()) {
    ostr << vec.front();
    for (auto itr = ++vec.begin(); itr != vec.end(); itr++) ostr << " " << *itr;
  }
  return ostr;
}
template <typename T>
ostream& operator<<(ostream& ostr, vector<vector<T>>& mat) {
  if (!mat.empty()) {
    ostr << mat.front();
    for (auto itr = ++mat.begin(); itr != mat.end(); itr++)
      ostr << endl << *itr;
  }
  return ostr;
}
template <typename T, typename U>
ostream& operator<<(ostream& ostr, pair<T, U>& p) {
  ostr << p.first << " " << p.second;
  return ostr;
}
template <typename T, typename U>
ostream& operator<<(ostream& ostr, vector<pair<T, U>>& mat) {
  if (!mat.empty()) {
    ostr << mat.front();
    for (auto itr = ++mat.begin(); itr != mat.end(); itr++)
      ostr << endl << *itr;
  }
  return ostr;
}
long long bfs(vector<vector<char>>& s, long long h, long long w, long long x,
              long long y) {
  long long qx = x, qy = y, ans = 0;
  vector<pair<long long, long long>> qu(1, pair<long long, long long>{qx, qy});
  while (qu.size()) {
    vector<pair<long long, long long>> qu_new;
    for (long long i = 0; i < (qu.size()); i++) {
      qx = qu[i].first;
      qy = qu[i].second;
      if (qx < 0 || qx >= h || qy < 0 || qy >= w) continue;
      if (s[qx][qy] == '#' || s[qx][qy] == 'x') continue;
      if (s[qx][qy] == 'g') {
        qu_new.clear();
        break;
      }
      s[qx][qy] = 'x';
      qu_new.emplace_back(pair<long long, long long>{qx + 1, qy});
      qu_new.emplace_back(pair<long long, long long>{qx - 1, qy});
      qu_new.emplace_back(pair<long long, long long>{qx, qy + 1});
      qu_new.emplace_back(pair<long long, long long>{qx, qy - 1});
    }
    qu = qu_new;
    ans++;
  }
  ans--;
  return ans;
}
long long search(vector<vector<char>>& s, long long h, long long w, long long x,
                 long long y) {
  if (s[x][y] == '#') return 0;
  long long len, ans = 0;
  for (long long i = 0; i < (h); i++) {
    for (long long j = 0; j < (w); j++) {
      if (s[i][j] == '#') continue;
      vector<vector<char>> s_cp(h, vector<char>(w));
      copy(s.begin(), s.end(), s_cp.begin());
      s_cp[i][j] = 'g';
      len = bfs(s_cp, h, w, x, y);
      if (len > ans) ans = len;
    }
  }
  return ans;
}
int main() {
  long long h, w, len, ans = 0;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  cin >> s;
  for (long long i = 0; i < (h); i++) {
    for (long long j = 0; j < (w); j++) {
      len = search(s, h, w, i, j);
      if (len > ans) ans = len;
    }
  }
  cout << ans << endl;
  return 0;
}
