#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

template<class V, class Delta, class Index>
vector<ll> bfs(int n, V s, Delta delta, Index index) {
  vector<ll> dist(n,-1);
  queue<V> que;
  dist[index(s)] = 0;
  que.push(s);
  while(!que.empty()) {
    V v = que.front(); que.pop();
    auto update = [&](V t) {
      if (dist[index(t)] == -1) {
        dist[index(t)] = dist[index(v)]+1;
        que.push(t);
      }
    };
    delta(v,update);
  }
  return dist;
}

template<class F>
struct lattice_delta {
  int h,w;
  F check;
  const int dx[8] = {-1,0,1,0,-1,1,-1,1};
  const int dy[8] = {0,-1,0,1,-1,-1,1,1};
  lattice_delta(int h, int w, F f):h(h),w(w),check(f){}
  template<class G>
  void operator()(P v, G update) {
    int y = v.first, x = v.second;
    for (int i=0; i<4; ++i) {
      int ny = y+dy[i], nx = x+dx[i];
      if (nx<0 || ny<0 || nx>=w || ny>=h) continue;
      check(v, P(ny,nx), update);
    }
  }
};

template<class F>
lattice_delta<F> make_lattice_delta(int h, int w, F f) { return lattice_delta<F>(h, w, f); }

struct lattice_index {
  int h,w;
  lattice_index(int h, int w):h(h),w(w){}
  int operator()(P v){ return v.first*w+v.second;}
};

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  ll ans = 0;
  auto index = lattice_index(h,w);
  auto check = [&](P v, P t, auto update) {
    if (s[t.first][t.second] == '.') update(t);
  };
  auto delta = make_lattice_delta(h,w,check);
  rep(y,h) rep(x,w) {
    auto res = bfs(h*w, P(y,x), delta, index);
    rep(i,h*w) chmax(ans, res[i]);
  }
  cout << ans << endl;
  return 0;
}