#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
int ctoi(const char c) {
  if ('0' <= c && c <= '9') return (c - '0');
  return -1;
}
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll MOD = 1000000007;
constexpr ll INF = 1000000011;
constexpr ll MOD2 = 998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS = 10e-8;
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto&& x : v) is >> x;
  return is;
}
template <typename T, typename U>
istream& operator>>(istream& is, pair<T, U>& p) {
  is >> p.first;
  is >> p.second;
  return is;
}
template <typename T, typename U>
ostream& operator>>(ostream& os, const pair<T, U>& p) {
  os << p.first << ' ' << p.second;
  return os;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto i = begin(v); i != end(v); ++i) {
    if (i != begin(v)) os << ' ';
    os << *i;
  }
  return os;
}
ll A[1000][1000], B[10007], C, D, E, F, K, G, H, L, M, N, P, Q, R, W, X, Y, Z;
string S[100];
ll dp[1007][10007];
ll mx = 0, mi = INF;
void bfs(ll a, ll b) {
  if (A[a + 1][b] > A[a][b] && a < H - 1 && S[a + 1][b] == '.') {
    A[a + 1][b] = A[a][b] + 1;
    bfs(a + 1, b);
  }
  if (A[a - 1][b] > A[a][b] && a > 0 && S[a - 1][b] == '.') {
    A[a - 1][b] = A[a][b] + 1;
    bfs(a - 1, b);
  }
  if (A[a][b + 1] > A[a][b] && b < W - 1 && S[a][b + 1] == '.') {
    A[a][b + 1] = A[a][b] + 1;
    bfs(a, b + 1);
  }
  if (A[a][b - 1] > A[a][b] && b > 0 && S[a][b - 1] == '.') {
    A[a][b - 1] = A[a][b] + 1;
    bfs(a, b - 1);
  }
}
int main() {
  cin >> H >> W;
  for (ll i = 0; i < (H); ++i) {
    cin >> S[i];
  }
  for (ll i = 0; i < (H); ++i) {
    for (ll j = 0; j < (W); ++j) {
      for (ll k = 0; k < (H); ++k) {
        for (ll l = 0; l < (W); ++l) {
          A[k][l] = INF;
        }
      }
      A[i][j] = 1;
      if (S[i][j] == '.') {
        bfs(i, j);
      }
      for (ll k = 0; k < (H); ++k) {
        for (ll l = 0; l < (W); ++l) {
          if (A[k][l] != INF) {
            mx = max(mx, A[k][l]);
          }
        }
      }
    }
  }
  cout << mx - 1 << '\n';
}
