#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1 << 30;
ll h, w;
string a[22];
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
vector<vector<ll>> unko(int i, int j) {
  vector<vector<ll>> dist(h, vector<ll>(w, INF));
  queue<pair<int, int>> q;
  dist[i][j] = 0;
  q.emplace(i, j);
  while (q.size()) {
    int y = q.front().first;
    int x = q.front().second;
    q.pop();
    for (int d = 0; d < 4; ++d) {
      int ny = y + dy[d];
      int nx = x + dx[d];
      if (0 <= ny && ny < h && 0 <= nx && nx < w && a[ny][nx] == '.') {
        if (dist[ny][nx] > dist[y][x] + 1) {
          dist[ny][nx] = dist[y][x] + 1;
          q.emplace(ny, nx);
        }
      }
    }
  }
  return dist;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  for (int i = 0; i < (h); ++i) cin >> a[i];
  ll ans = 0;
  vector<vector<ll>> dist;
  bool ok = false;
  for (int i = 0; i < h; ++i) {
    if (ok) break;
    for (int j = 0; j < w; ++j) {
      if (a[i][j] == '.') {
        ok = true;
        dist = unko(i, j);
        break;
      }
    }
  }
  ll si, sj;
  ll mx = 0;
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j)
      if (a[i][j] == '.' && dist[i][j] > mx) {
        si = i, sj = j;
        mx = dist[i][j];
      }
  dist = unko(si, sj);
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j)
      if (a[i][j] == '.' && ans < dist[i][j]) ans = dist[i][j];
  cout << ans;
  return 0;
}
