#include <bits/stdc++.h>
constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  for (ll i = 0; i < ll(h); ++i) cin >> v[i];
  auto solve = [&](int sx, int sy) {
    vvi dist(h, vi(w, 1000000001ll));
    dist[sx][sy] = 0;
    queue<pii> q;
    q.push({sx, sy});
    while (!q.empty()) {
      auto p = q.front();
      q.pop();
      for (ll k = 0; k < ll(4); ++k) {
        int x = p.first + dx[2 * k], y = p.second + dy[2 * k];
        if (x < 0 || x >= h || y < 0 || y >= w || v[x][y] == '#') continue;
        if (chmin(dist[x][y], dist[p.first][p.second] + 1)) {
          q.push({x, y});
        }
      }
    }
    int ans = 0;
    for (ll i = 0; i < ll(h); ++i)
      for (ll j = 0; j < ll(w); ++j)
        if (dist[i][j] != 1000000001ll) chmax(ans, dist[i][j]);
    return ans;
  };
  int ans = 0;
  for (ll i = 0; i < ll(h); ++i)
    for (ll j = 0; j < ll(w); ++j) chmax(ans, solve(i, j));
  cout << ans << endl;
}
