#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}



int main(){
  ll H,W;
  cin>>H>>W;
  vector<string> S(H);
  REP(H){
    cin>>S[i];
  }
  ll ans=0;
  For(i,H){
    For(j,W){
      dump(i);
      dump(j);
      deque<pair<pll,ll>> q;
      set<pll> s;
      q.push_back(make_pair(pll(i,j),0));
      s.insert(pll(i,j));
      while(!q.empty()){
        auto tmp = q.back();q.pop_back();
        dump(tmp);
        ans=max(ans,tmp.second);
        ll curx=tmp.first.first,cury=tmp.first.second;
        for (int y = -1; y < 2; y+=2)
        {
          int x=0;
          if(curx+x<0 || curx+x>=H || cury+y<0 || cury+y >= W 
            || S[curx+x][cury+y]=='#' ||s.count(pll(curx+x,cury+y))){
            continue;
          }
          s.insert(pll(curx+x,cury+y));
          q.push_front(make_pair(pll(curx+x,cury+y),tmp.second+1));
        }
        for (int x=-1;x<2;x+=2)
        {
          int y=0;
          if(curx+x<0 || curx+x>=H || cury+y<0 || cury+y >= W 
            || S[curx+x][cury+y]=='#' ||s.count(pll(curx+x,cury+y))){
            continue;
          }
          s.insert(pll(curx+x,cury+y));
          q.push_front(make_pair(pll(curx+x,cury+y),tmp.second+1));
        }
      }
    }
  }
  cout<<ans<<endl;
    return 0;
}
