#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

constexpr ll dx[]={1,0,-1,0,1,1,-1,-1};
constexpr ll dy[]={0,1,0,-1,1,-1,1,-1};

int main(){

  int h,w;
  cin>>h>>w;
  vector<string> s(h);
  cin>>s;

  auto calc = [&](int i,int j){
    auto dist = _vec<ll>(h,w,INF);
    queue<tuple<ll,ll,ll>> que;
    que.emplace(i,j,0);
    while(!que.empty()){
      ll y,x,c;
      tie(y,x,c) = que.front();
      que.pop();
      if(chmin(dist[y][x],c)){
        rep(i,4){
          ll ny=y+dy[i];
          ll nx=x+dx[i];
          if(ny==-1||nx==-1||ny==h||nx==w)continue;
          if(s[ny][nx]=='#')continue;
          que.emplace(ny,nx,c+1);
        }
      }
    }
    ll res=-1;
    rep(i,h)rep(j,w)if(dist[i][j]!=INF)res=max(res,dist[i][j]);
    return res;
  };

  ll ans = 0;
  rep(i,h)rep(j,w){
    ans = max(ans,calc(i,j));
  }
  cout<<(ans)<<endl;

}