#include <bits/stdc++.h>
using namespace std;
void ans(bool b) { cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) a = b;
  return a < b;
}
template <typename T>
inline bool chmin(T& a, T b) {
  if (b < a) a = b;
  return b < a;
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
  fill((T*)array, (T*)(array + N), val);
}
template <typename T>
void vdeb(T v) {
  cout << "#vector set debug" << endl;
  for (auto vv : v) cout << vv << " ";
  cout << endl;
}
template <typename T1, typename T2>
void adeb(T1 arr[], T2 n) {
  cout << "#adebug" << endl;
  for (int i = 0; i <= n; i++) cout << arr[i] << " ";
  cout << endl;
}
template <typename T1>
void mdeb(T1 mp) {
  cout << "#map pair debug" << endl;
  for (auto const& m : mp) cout << m.first << " " << m.second << endl;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
class DMazeMaster {
 public:
  void solve(std::istream& in, std::ostream& out) {
    int h, w;
    in >> h >> w;
    char s[100][100];
    for (long long i = 0; i < h; i++) {
      for (long long j = 0; j < w; j++) {
        in >> s[i][j];
      }
    }
    int res = 0;
    for (long long si = 0; si < h; si++) {
      for (long long sj = 0; sj < w; sj++) {
        if (s[si][sj] == '#') continue;
        for (long long gi = 0; gi < h; gi++) {
          for (long long gj = 0; gj < w; gj++) {
            vector<vector<int>> visit(h, vector<int>(w, 0));
            int mi = 1e6;
            function<void(int, int, int, vector<vector<int>>)> dfs =
                [&](int x, int y, int sum, vector<vector<int>> visit) {
                  if (x == gj && y == gi) {
                    chmin(mi, sum);
                    return;
                  }
                  for (long long i = 0; i < 4; i++) {
                    int dly = y + dy[i];
                    int dlx = x + dx[i];
                    if (dlx < 0 || dlx >= w || dly < 0 || dly >= h) continue;
                    if (visit[dly][dlx]) continue;
                    if (s[dly][dlx] == '#') continue;
                    visit[dly][dlx] = 1;
                    dfs(dlx, dly, sum + 1, visit);
                    visit[dly][dlx] = 0;
                  }
                };
            dfs(sj, si, 0, visit);
            if (mi != 1e6) chmax(res, mi);
          }
        }
      }
    }
    out << res << endl;
  }
};
int main() {
  DMazeMaster solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
