#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using ll = long long;
constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);
using namespace std;
void scans(string& str) {
  char c;
  str = "";
  scanf("%c", &c);
  if (c == '\n') scanf("%c", &c);
  while (c != '\n' && c != -1) {
    str += c;
    scanf("%c", &c);
  }
}
void scanc(char& str) {
  char c;
  scanf("%c", &c);
  if (c == -1) return;
  while (c == '\n') {
    scanf("%c", &c);
  }
  str = c;
}
double acot(double x) { return PI / 2 - atan(x); }
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll number1, ll number2) {
  return number1 / gcd(number1, number2) * number2;
}
ll LSB(ll n) { return (n & (-n)); }
void WarshallFloyd(int n, vector<vector<ll>>& d) {
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (n); ++j) {
      for (int k = 0; k < (n); ++k) {
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
      }
    }
  }
}
int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  vector<vector<ll>> a(h, vector<ll>(w)), b(h * w, vector<ll>(w * h));
  for (int i = 0; i < (h * w); ++i) fill((b[i]).begin(), (b[i]).end(), INF);
  string s;
  for (int i = 0; i < (h); ++i) {
    scans(s);
    for (int j = 0; j < (w); ++j) {
      a[i][j] = (s[j] == '.');
    }
  }
  for (int i = 0; i < (h - 1); ++i) {
    for (int j = 0; j < (w); ++j) {
      if (a[i][j] && a[i + 1][j])
        b[i * w + j][(i + 1) * w + j] = b[(i + 1) * w + j][i * w + j] = 1;
    }
  }
  for (int i = 0; i < (w - 1); ++i) {
    for (int j = 0; j < (h); ++j) {
      if (a[j][i] && a[j][i + 1])
        b[j * w + i][j * w + i + 1] = b[j * w + i + 1][j * w + i] = 1;
    }
  }
  WarshallFloyd(w * h, b);
  ll ans = 0;
  for (int i = 0; i < (w * h); ++i) {
    for (int j = 0; j < (w * h); ++j) {
      if (b[i][j] < INF) ans = max(ans, b[i][j]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
