#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T>
using vec = vector<T>;
static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI =
    static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static map<type_index, const char* const> scanType = {{typeid(int), "%d"},
                                                      {typeid(ll), "%lld"},
                                                      {typeid(double), "%lf"},
                                                      {typeid(char), "%c"}};
template <class T>
static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T>
static inline bool chmax(T& a, T b);
template <class T>
static inline bool chmin(T& a, T b);
template <class T>
static inline T gcd(T a, T b);
template <class T>
static inline T lcm(T a, T b);
template <class A, size_t N, class T>
static void Fill(A (&arr)[N], const T& val);
template <class T>
T mod(T a, T m);
int memo[20][20][20][20];
int main(int argc, char* argv[]) {
  ll h, w;
  cin >> h >> w;
  vec<vec<char>> maze(h, vec<char>(w));
  for (int i = (0); i < (h); i++)
    for (int j = (0); j < (w); j++) cin >> maze[i][j];
  Fill(memo, -1LL);
  int ans = 0;
  vec<i_i> dd{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  for (int i = (0); i < (h); i++)
    for (int j = (0); j < (w); j++) {
      if (maze[i][j] == '#') continue;
      deque<pair<i_i, int>> q;
      q.push_back({{i, j}, 0});
      while (!q.empty()) {
        pair<i_i, int> cur = q.front();
        q.pop_front();
        memo[i][j][cur.first.first][cur.first.second] = cur.second;
        chmax(ans, cur.second);
        for (auto p : dd) {
          i_i ne = {cur.first.first + p.first, cur.first.second + p.second};
          if (ne.first == i && ne.second == j) continue;
          if (ne.first < 0 || ne.first >= h || ne.second < 0 || ne.second >= w)
            continue;
          if (memo[i][j][ne.first][ne.second] > -1 ||
              maze[ne.first][ne.second] == '#')
            continue;
          q.push_back({{ne.first, ne.second}, cur.second + 1});
        }
      }
    }
  ((cout) << (ans) << (endl));
  return 0;
}
template <class T>
static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}
static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }
  int i = 0, size = v.size();
  string s;
  getline(cin, s);
  if (s.size() != 0) {
    i++;
    v[0] = s;
  }
  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline T gcd(T a, T b) {
  return __gcd(a, b);
}
template <class T>
inline T lcm(T a, T b) {
  T c = min(a, b), d = max(a, b);
  return c * (d / gcd(c, d));
}
template <class A, size_t N, class T>
void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}
template <class T>
T mod(T a, T m) {
  return (a % m + m) % m;
}
