#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)

const int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};

int H, W;
vector<string> S;

int search(pair<int, int> pos) {
  map<pair<int, int>, int> s;
  queue<pair<int, int>> q;
  s[pos] = 0;
  q.push(pos);
  int md = -1;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    int d = s[p];
    md = max(md, d);
    rep(i, 4) {
      int x = p.first + dx[i], y = p.second + dy[i];
      auto np = make_pair(x, y);
      if (s.find(np) != s.end() || x < 0 || x >= W || y < 0 || y >= H ||
          S[y][x] != '.')
        continue;
      s[np] = d + 1;
      q.push(np);
    }
  }
  return md;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W;
  S.resize(H);
  rep(i, H) cin >> S[i];
  int ans = 0;
  rep(y, H) rep(x, W) if (S[y][x] == '.') ans = max(ans, search({x, y}));
  cout << ans << endl;
  return 0;
}
