#include <bits/stdc++.h>

template <typename T>
class Grid {
  template <typename U>
  using pqueue = std::priority_queue<U, std::vector<U>, std::greater<U>>;
  using grid = std::vector<std::vector<std::optional<T>>>;

 public:
  Grid(int r, int c)
      : r_(r), c_(c), grid_(r, std::vector<std::optional<T>>(c)) {}
  bool Inside(int r, int c) const {
    return 0 <= r && r < r_ && 0 <= c && c < c_;
  }
  void Set(int r, int c, T v) {
    assert(Inside(r, c));
    grid_[r][c] = v;
  }
  grid Distance(int sr, int sc) const {
    assert(Inside(sr, sc));
    assert(grid_[sr][sc]);
    pqueue<std::tuple<T, int, int>> que;
    que.emplace(0, sr, sc);
    grid dist(r_, std::vector<std::optional<T>>(c_));
    dist[sr][sc] = 0;
    while (!que.empty()) {
      auto [d, r, c] = que.top();
      que.pop();
      for (int i = 0; i < 4; ++i) {
        const int dr[] = {1, -1, 0, 0};
        const int dc[] = {0, 0, 1, -1};
        int nr = r + dr[i];
        int nc = c + dc[i];
        if (!Inside(nr, nc) || !grid_[nr][nc]) {
          continue;
        }
        T nd = d + *grid_[nr][nc];
        std::optional<T>& di = dist[nr][nc];
        if (di && *di <= nd) {
          continue;
        }
        di = nd;
        que.emplace(nd, nr, nc);
      }
    }
    return dist;
  }

 private:
  const int r_, c_;
  grid grid_;
};

template <typename T, typename = void>
struct is_iterable : std::false_type {};
template <typename T>
struct is_iterable<T, std::void_t<decltype(std::begin(std::declval<T>())),
                                  decltype(std::end(std::declval<T>()))>>
    : std::true_type {};

template <typename T, typename = void>
struct is_pair : std::false_type {};
template <typename T>
struct is_pair<T, std::void_t<decltype(std::declval<T>().first),
                              decltype(std::declval<T>().second)>>
    : std::true_type {};

template <typename T>
void debug(const T& v) {
  if constexpr (is_pair<T>::value) {
    std::cerr << "{";
    debug(v.first);
    std::cerr << ", ";
    debug(v.second);
    std::cerr << "}";
  } else if constexpr (is_iterable<T>::value &&
                       !std::is_same<T, std::string>::value) {
    std::cerr << "{";
    for (auto it = v.begin(); it != v.end(); ++it) {
      if (it != v.begin()) std::cerr << ", ";
      debug(*it);
    }
    std::cerr << "}";
  } else {
    std::cerr << v;
  }
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  debug(value);
  std::cerr << ", ";
  debug(args...);
}
#if DEBUG
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);
#define ints(...) rd(int, __VA_ARGS__);
#define strings(...) rd(string, __VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  if constexpr (std::is_same<T, bool>::value) {
    std::cout << (value ? "Yes" : "No");
  } else {
    std::cout << value;
  }
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  write_to_cout(value);
  std::cout << ' ';
  write_to_cout(args...);
}
#define wt(...)                 \
  do {                          \
    write_to_cout(__VA_ARGS__); \
    cout << '\n';               \
  } while (0)

#define all(x) (x).begin(), (x).end()

#define rep_dispatch(_1, _2, _3, name, ...) name
#define rep3(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep2(i, n) rep3(i, 0, n)
#define rep1(n) rep2(_loop_variable_, n)
#define rep(...) rep_dispatch(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)

#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
  for (T& vi : v) is >> vi;
  return is;
}

template <typename T, typename U>
bool chmax(T& a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T, typename U>
bool chmin(T& a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
int sz(const T& v) {
  return v.size();
}

#include <boost/hana/functional/fix.hpp>
const auto& Fix = boost::hana::fix;

using ll = long long;

template <typename T>
using low_priority_queue =
    std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

int main() {
  ints(H, W);
  vector<string> m(H);
  cin >> m;

  Grid<int> grid(H, W);
  rep(r, H) rep(c, W) if (m[r][c] == '.') grid.Set(r, c, 1);

  int ans = 0;
  rep(sr, H) rep(sc, W) if (m[sr][sc] == '.') {
    VV<optional<int>> dist = grid.Distance(sr, sc);
    rep(r, H) rep(c, W) if (optional<int> d = dist[r][c]; d) chmax(ans, *d);
  }
  wt(ans);
}


Measured memory_bytes: 3624