#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const long long INF = 1e9 + 10;
const long long mod = 998244353;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int N, M, L, Q;
int V;
long long d[500][500];
void warshal_floyd(void) {
  for (int k = 0; k < V; k++)
    for (int i = 0; i < V; i++)
      for (int j = 0; j < V; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  return;
}
int main() {
  string S[100];
  int H, W;
  cin >> H >> W;
  V = H * W;
  for (int i = 0; i < V; i++)
    for (int j = 0; j < V; j++) d[i][j] = (1e9 + 1);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  for (int now = 0; now < H * W; now++) {
    int i = now / W;
    int j = now % W;
    if (S[i][j] == '.') {
      if (now / W >= 1 && S[i - 1][j] != '#') {
        d[now][now - W] = 1;
        d[now - W][now] = 1;
      }
      if (now / W < H - 1 && S[i + 1][j] != '#') {
        d[now][now + W] = 1;
        d[now + W][now] = 1;
      }
      if (now % W >= 1 && S[i][j - 1] != '#') {
        d[now][now - 1] = 1;
        d[now - 1][now] = 1;
      }
      if (now % W < W - 1 && S[i][j + 1] != '#') {
        d[now][now + 1] = 1;
        d[now + 1][now] = 1;
      }
    }
  }
  warshal_floyd();
  int ans = -1;
  for (int i = 0; i < H * W; i++)
    for (int j = 0; j < H * W; j++) {
      if (d[i][j] != (1e9 + 1) && d[i][j] >= ans) {
        ans = d[i][j];
      }
    }
  cout << ans;
  return 0;
}
