#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll adj[(ll)(500 + 4)][(ll)(500 + 4)];
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(nullptr);
  ;
  ll n, m;
  ll ar[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  cin >> n >> m;
  char ch[n][m];
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < m; j++) {
      cin >> ch[i][j];
    }
  }
  ll nn = n * m;
  for (ll i = 0; i < nn; i++) {
    for (ll j = 0; j < nn; j++) {
      adj[i][j] = (ll)(1e9 + 7);
    }
  }
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < m; j++) {
      if (ch[i][j] == '#') {
        continue;
      }
      for (ll k = 0; k < 4; k++) {
        ll x = i + ar[k][0], y = j + ar[k][1];
        if (x >= 0 && x < n && y >= 0 && y < m && ch[x][y] == '.') {
          ll u = m * x + y, v = i * m + j;
          adj[u][v] = 1;
          adj[v][u] = 1;
        }
      }
    }
  }
  ll ma = 0;
  for (ll k = 0; k < n * m; k++) {
    for (ll i = 0; i < n * m; i++) {
      for (ll j = 0; j < n * m; j++) {
        adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
      }
    }
  }
  for (ll k = 0; k < n * m; k++) {
    for (ll i = 0; i < n * m; i++) {
      if (adj[k][i] == (ll)(1e9 + 7)) {
        continue;
      }
      ma = max(adj[k][i], ma);
    }
  }
  cout << ma << "\n";
}
