#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PP = pair<pair<ll, ll>, ll>;
int main() {
  ll h, w;
  scanf("%lld %lld", &h, &w);
  char fig[h + 2][w + 2];
  for (ll i = 0; i < h + 2; i++) {
    fig[i][0] = '#';
    fig[i][w + 1] = '#';
  }
  for (ll i = 0; i < w + 2; i++) {
    fig[0][i] = '#';
    fig[h + 1][i] = '#';
  }
  for (ll i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (ll j = 0; j < w; j++) fig[i + 1][j + 1] = s[j];
  }
  ll ans = 0;
  ll dx[] = {0, 1, 0, -1};
  ll dy[] = {1, 0, -1, 0};
  ll used[h + 2][w + 2], disdis[h + 2][w + 2];
  for (ll i = 1; i <= h; i++) {
    for (ll j = 1; j <= w; j++) {
      for (ll ii = 0; ii < h + 2; ii++)
        for (ll jj = 0; jj < w + 2; jj++) used[ii][jj] = 0;
      for (ll ii = 0; ii < h + 2; i++)
        for (ll jj = 0; jj < w + 2; jj++) disdis[ii][jj] = 1e11;
      queue<PP> que;
      que.push({{i, j}, 0});
      while (!que.empty()) {
        PP pp = que.front();
        que.pop();
        ll I = pp.first.first, J = pp.first.second, dist = pp.second;
        if (used[I][J] and disdis[I][J] < dist) continue;
        disdis[I][J] = min(disdis[I][J], dist);
        used[I][J] = 1;
        for (ll d = 0; d < 4; d++) {
          ll ti = I + dx[d], tj = J + dy[d];
          if (fig[ti][tj] != '#' and !used[ti][tj]) {
            que.push({{ti, tj}, disdis[I][J] + 1});
          }
        }
      }
      ll tmp = 0;
      for (ll ii = 1; ii < h + 1; ii++)
        for (ll jj = 1; jj < w + 1; jj++) {
          if (fig[ii][jj] != '#') tmp = max(tmp, disdis[ii][jj]);
        }
      ans = max(ans, tmp);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
