#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
int add(int a, int b) {
  if (a + b >= mod) return a + b - mod;
  return a + b;
}
int mul(int a, int b) { return 1LL * a * b % mod; }
int power(int a, int b) {
  if (b < 0) return 0;
  int re = 1;
  while (b) {
    if (b & 1) {
      re = mul(re, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return re;
}
int const N = 100000 + 5;
int fact[N], inverse[N];
void FAC() {
  fact[0] = 1;
  for (int x = 1; x < N; x++) {
    fact[x] = mul(fact[x - 1], x);
  }
  inverse[N - 1] = power(fact[N - 1], mod - 2);
  for (int x = N - 2; x >= 0; x--) {
    inverse[x] = mul(x + 1, inverse[x + 1]);
  }
}
int ncr(int a, int b) {
  if (a < b) return 0;
  return mul(fact[a], mul(inverse[a - b], inverse[b]));
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<string> vec(n);
  for (auto &a : vec) cin >> a;
  int h = n * m;
  vector<vector<int>> ans(h, vector<int>(h, 1e5));
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < m; y++) {
      if (vec[x][y] == '.') {
        if (x - 1 != -1 && vec[x - 1][y] == '.') {
          int x1 = (x - 1) * n + y;
          ans[x * n + y][x1] = 1;
        }
        if (y - 1 != -1 && vec[x][y - 1] == '.') {
          int x1 = x * n + y - 1;
          ans[x * n + y][x1] = 1;
        }
        if (x + 1 != n && vec[x + 1][y] == '.') {
          int x1 = (x + 1) * n + y;
          ans[x * n + y][x1] = 1;
        }
        if (y + 1 != m && vec[x][y + 1] == '.') {
          int x1 = x * n + y + 1;
          ans[x * n + y][x1] = 1;
        }
      }
    }
  }
  for (int k = 0; k < h; k++) {
    for (int x = 0; x < h; x++) {
      for (int y = 0; y < h; y++) {
        if (ans[x][k] + ans[k][y] < ans[x][y])
          ans[x][y] = ans[x][k] + ans[k][y];
      }
    }
  }
  int u = 0;
  for (int x = 0; x < h; x++) {
    for (int y = 0; y < h; y++) {
      if (ans[x][y] < 1e5) {
        u = max(u, ans[x][y]);
      }
    }
  }
  cout << u;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
