#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  return b ? gcd(b, a % b) : a;
}
unsigned long long lcm(unsigned long long a, unsigned long long b) {
  return a / gcd(a, b) * b;
}
int h, w;
int tov(int y, int x) { return (y * w + x); }
const vector<int> di = {-1, 0, 1, 0}, dj = {0, 1, 0, -1};
int main() {
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0, i_len = (h); i < i_len; i++) cin >> s[i];
  vector<vector<int> > dist(h * w, vector<int>(h * w, (1e9)));
  for (int i = 0, i_len = (h); i < i_len; i++)
    for (int j = 0, j_len = (w); j < j_len; j++) {
      if (s[i][j] == '#') continue;
      int val = tov(i, j);
      dist[val][val] = 0;
    }
  for (int pi = 0, pi_len = (h); pi < pi_len; pi++)
    for (int pj = 0, pj_len = (w); pj < pj_len; pj++) {
      if (s[pi][pj] == '#') continue;
      for (int j = 0, j_len = (4); j < j_len; j++) {
        int ni = pi + di[j], nj = pj + dj[j];
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        int from = tov(pi, pj), to = tov(ni, nj);
        dist[from][to] = 1;
      }
    }
  for (int k = 0, k_len = (h * w); k < k_len; k++)
    for (int i = 0, i_len = (h * w); i < i_len; i++)
      for (int j = 0, j_len = (h * w); j < j_len; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
  int ans = 0;
  for (int i = 0, i_len = (h * w); i < i_len; i++)
    for (int j = 0, j_len = (h * w); j < j_len; j++) {
      if (dist[i][j] == (1e9)) continue;
      ans = max(ans, dist[i][j]);
    }
  cout << ans << endl;
  return 0;
}
