#include <bits/stdc++.h>
using namespace std;
using int32 = int_fast32_t;
using int64 = int_fast64_t;
const int32 INF = 1e9;
const int32 MOD = 1e9 + 7;
const int64 LLINF = 1e18;
int32 di[4] = {0, 1, 0, -1};
int32 dj[4] = {1, 0, -1, 0};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int64 i = 0; i < (h); ++i) cin >> s[i];
  vector<vector<int32>> dist;
  int32 ans = 0;
  for (int64 si = 0; si < (h); ++si)
    for (int64 sj = 0; sj < (h); ++sj) {
      queue<pair<int32, int32>> que;
      que.emplace(si, sj);
      dist = vector<vector<int32>>(h, vector<int32>(w, INF));
      dist[si][sj] = 0;
      while (!que.empty()) {
        int32 ci, cj;
        tie(ci, cj) = que.front();
        que.pop();
        for (int64 i = 0; i < (4); ++i) {
          int32 ni = ci + di[i];
          int32 nj = cj + dj[i];
          if (ni < 0 || h <= ni) continue;
          if (nj < 0 || w <= nj) continue;
          if (s[ni][nj] == '#') continue;
          if (dist[ni][nj] > dist[ci][cj] + 1) {
            dist[ni][nj] = dist[ci][cj] + 1;
            que.emplace(ni, nj);
          }
        }
      }
      for (int64 i = 0; i < (h); ++i)
        for (int64 j = 0; j < (w); ++j) {
          if (dist[i][j] != INF && dist[i][j] > ans) {
            ans = dist[i][j];
          }
        }
    }
  cout << (ans) << "\n";
  return 0;
}
