#include <bits/stdc++.h>
template <class T>
inline T chmax(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T>
inline T chmin(T& a, const T b) {
  return a = (a > b) ? b : a;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
const ll INF = 1e18;
using namespace std;
ll H, W;
ll dx[4] = {0, 0, 1, -1};
ll dy[4] = {1, -1, 0, 0};
ll ans = 0;
vector<string> vec;
vector<vector<ll>> dist;
void bfs(ll x, ll y) {
  queue<pair<ll, ll>> q;
  q.push(make_pair(x, y));
  for (ll i = 0; i < ll(H); ++i)
    for (ll j = 0; j < ll(W); ++j) dist[i][j] = -1;
  dist[x][y] = 0;
  while (!q.empty()) {
    x = q.front().first;
    y = q.front().second;
    q.pop();
    chmax(ans, dist[x][y]);
    for (ll i = 0; i < ll(4); ++i) {
      ll xx = x + dx[i];
      ll yy = y + dy[i];
      if ((xx < 0 || H <= xx)) continue;
      if ((yy < 0 || W <= yy)) continue;
      if (vec[xx][yy] == '#') continue;
      if (dist[xx][yy] != -1) continue;
      dist[xx][yy] = dist[x][y] + 1;
      q.push(make_pair(xx, yy));
    }
  }
}
signed main() {
  cin >> H >> W;
  vec = vector<string>(H);
  dist = vector<vector<ll>>(H, vector<ll>(W));
  for (ll i = 0; i < ll(H); ++i) cin >> vec[i];
  for (ll i = 0; i < ll(H); ++i)
    for (ll j = 0; j < ll(W); ++j) bfs(i, j);
  cout << ans << endl;
  return 0;
}
