#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int LARGE_INT = 1e9 + 100;
const int INF = 1e9 + 7;
const long long INF_LL = (long long)INF * 300 * 300;
const int MOD = 1e9 + 7;
long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}
long long modinv(long long a) {
  long long b = MOD, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0) u += MOD;
  return u;
}
long long moddev(long long a, long long b) { return a * modinv(b) % MOD; }
vector<vector<int>> m;
void warshall_floyd(int n) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++) m[j][k] = min(m[j][k], m[j][i] + m[i][k]);
}
void Main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h);
  for (int i = (0); i < (h); ++i) {
    s[i].resize(w);
    for (int j = (0); j < (w); ++j) {
      cin >> s[i][j];
    }
  }
  m.resize(h * w);
  for (int i = (0); i < (h * w); ++i) {
    m[i].resize(h * w, INF);
  }
  for (int i = (0); i < (h); ++i) {
    for (int j = (0); j < (w); ++j) {
      if (i == j) {
        m[i][j] = 0;
      }
      if (s[i][j] == '#') {
        continue;
      }
      if (i != 0 && s[i - 1][j] == '.') {
        m[i * w + j][(i - 1) * w + j] = 1;
        m[(i - 1) * w + j][i * w + j] = 1;
      }
      if (i != h - 1 && s[i + 1][j] == '.') {
        m[i * w + j][(i + 1) * w + j] = 1;
        m[(i + 1) * w + j][i * w + j] = 1;
      }
      if (j != 0 && s[i][j - 1] == '.') {
        m[i * w + j][i * w + j - 1] = 1;
        m[i * w + j - 1][i * w + j] = 1;
      }
      if (i != w - 1 && s[i][j + 1] == '.') {
        m[i * w + j][i * w + j + 1] = 1;
        m[i * w + j + 1][i * w + j] = 1;
      }
    }
  }
  warshall_floyd(h * w);
  int result = 0;
  for (int i = (0); i < (h * w); ++i) {
    for (int j = (0); j < (h * w); ++j) {
      if (m[i][j] != INF) {
        result = max(result, m[i][j]);
      }
    }
  }
  cout << result << endl;
  return;
}
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}
