#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 1001001001;
const long long INFL = (1LL << 60);
const double eps = (1e-9);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int bfs(const vector<string>& m, int sh, int sw, int gh, int gw) {
  queue<pair<int, int>> q;
  q.push(make_pair(sh, sw));
  const int H = m.size();
  const int W = m[0].size();
  vector<vector<int>> d(H, vector<int>(W, INF));
  d[sh][sw] = 0;
  while (q.size()) {
    pair<int, int> p = q.front();
    q.pop();
    if (p.first == gh && p.second == gw) break;
    for (int i = 0; i < 4; i++) {
      int nh = p.first + dx[i], nw = p.second + dy[i];
      if (nw < 0 || nw >= W || nh < 0 || nh >= H || m[nh][nw] == '#' ||
          d[nh][nw] != INF)
        continue;
      q.push(make_pair(nh, nw));
      d[nh][nw] = d[p.first][p.second] + 1;
    }
  }
  return d[gh][gw];
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (long long i = 0; i < h; ++i) cin >> s[i];
  int ans = 0;
  for (long long sw = 0; sw < w; ++sw) {
    for (long long sh = 0; sh < h; ++sh) {
      for (long long gw = 0; gw < w; ++gw) {
        for (long long gh = 0; gh < h; ++gh) {
          int tmp = bfs(s, sh, sw, gh, gw);
          if (tmp != INF) chmax(ans, tmp);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
