#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}
// auto v = make_vec<int>(h, w);
// fill(v, 0);

signed main(){

  int h, w; cin >> h >> w;
  vector<string> s(h);
  for(int i = 0; i < h; i++){
    cin >> s[i];
  }

  int ans = 0;
  auto dp = make_vec<int>(h, w);
  function< void(int,int) > dfs =
  [&](int y, int x){
    int dx[4] = {1,0,-1,0}, dy[4] = {0,-1,0,1};
    for(int i = 0; i < 4; i++){
      int ny = y + dy[i];
      int nx = x + dx[i];
      if(ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
      if(s[ny][nx] == '.' && dp[ny][nx] > dp[y][x] + 1){
        dp[ny][nx] = dp[y][x] + 1;
        dfs(ny, nx);
      }
    }
    return;
  };

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      fill(dp, INF);
      dp[i][j] = 0;
      dfs(i, j);
      for(int k = 0; k < h; k++){
        for(int l = 0; l < w; l++){
          if(dp[k][l] != INF) ans = max(ans, dp[k][l]);
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}
