#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, nx, ny, ans = 0;
  vector<long long> dx{1, -1, 0, 0}, dy{0, 0, 1, -1};
  vector<vector<long long>> v(h, vector<long long>(w, 0));
  queue<pair<int64_t, pair<long long, long long>>> qu;
  qu.emplace(0, pair<long long, long long>{qx, qy});
  while (!qu.empty()) {
    qx = qu.front().second.first;
    qy = qu.front().second.second;
    ans = qu.front().first + 1;
    qu.pop();
    v[qx][qy] = 1;
    for (long long j = 0; j < (4); j++) {
      nx = qx + dx[j];
      ny = qy + dy[j];
      if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
      if (s[nx][ny] == '#' || v[nx][ny] == 1) continue;
      qu.emplace(ans, pair<long long, long long>{nx, ny});
    }
  }
  ans--;
  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++) {
      if (s[i][j] == '#') continue;
      len = bfs(s, h, w, i, j);
      if (len > ans) ans = len;
    }
  }
  cout << ans << endl;
  return 0;
}
