#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using ll = long long;
using P = pair<ll, ll>;
constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
class DMazeMaster {
 public:
  int h, w;
  int p(int i, int j) { return i * w + j; }
  void solve(istream& cin, ostream& cout) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> h >> w;
    vector<vector<ll>> dp(h * w, vector<ll>(h * w, LLONG_MAX / 2));
    vector<vector<bool>> mat(h, vector<bool>(w));
    for (int i = 0; i < (int)(h); i++) {
      for (int j = 0; j < (int)(w); j++) {
        char c;
        cin >> c;
        if (c == '.') {
          mat[i][j] = true;
        }
      }
    }
    for (int i = 0; i < (int)(h); i++) {
      for (int j = 0; j < (int)(w); j++) {
        if (mat[i][j]) {
          if (i > 0 && mat[i - 1][j]) {
            dp[p(i, j)][p(i - 1, j)] = 1;
          }
          if (i < h - 1 && mat[i + 1][j]) {
            dp[p(i, j)][p(i + 1, j)] = 1;
          }
          if (j > 0 && mat[i][j - 1]) {
            dp[p(i, j)][p(i, j - 1)] = 1;
          }
          if (j < w - 1 && mat[i][j + 1]) {
            dp[p(i, j)][p(i, j + 1)] = 1;
          }
        }
      }
    }
    int n = h * w;
    for (int k = 0; k < (int)(n); k++) {
      for (int i = 0; i < (int)(n); i++) {
        for (int j = 0; j < (int)(n); j++) {
          chmin(dp[i][j], dp[i][k] + dp[k][j]);
        }
      }
    }
    ll ans = 0;
    for (int i = 0; i < (int)(n); i++) {
      for (int j = 0; j < (int)(n); j++) {
        if (dp[i][j] != LLONG_MAX / 2) {
          chmax(ans, dp[i][j]);
        }
      }
    }
    cout << ans << endl;
  }
};
signed main() {
  DMazeMaster solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
