#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 2e18
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
char mat[21][21];
int x[] = {-1,1,0,0};
int y[] =  {0,0,1,-1};
int h,w;
bool vis[21][21];
bool isv(int a,int b)
{
          if(a<h && a >=0)
          {
                    if(b<w && b>=0)
                    {
                              return true;
                    }
          }
          return false;
}
int f(int x1,int y1,int x2,int y2)
{
          queue<tuple<int,int,int>> q;
          q.push(make_tuple(x1,y1,0));
          vis[x1][y1] = true;
          while(!q.empty())
          {
                    int cx = get<0>(q.front());
                    int cy = get<1>(q.front());
                    int zz = get<2>(q.front());
                    q.pop();
                    if(cx == x2 && cy == y2){
                              return zz;
                    }
                    fri(i,0,4)
                    {
                              if(isv(cx+x[i],cy+y[i]))
                              {
                                        if(!vis[cx+x[i]][cy+y[i]])
                                        {
                                                  if(mat[cx+x[i]][cy+y[i]] == '.')
                                                  {
                                                            q.push(make_tuple(cx+x[i],cy+y[i],zz+1));
                                                            vis[cx+x[i]][cy+y[i]] = true;
                                                  }
                                        }
                              }
                    }
          }
          return 0;
}
int main()
{
          //int h,w;
          cin>>h>>w;
          fri(i,0,h)
          {
                    fri(j,0,w)
                    {
                              cin>>mat[i][j];
                    }
          }
          int ans = 0;
          fri(i,0,h)
          {
                    fri(j,0,w)
                    {
                              fri(i1,0,h)
                              {
                                        fri(j1,0,w)
                                        {
                                                  if(mat[i][j] == '.' && mat[i1][j1] == '.')
                                                  {
                                                            memset(vis,false,sizeof vis);
                                                            ans = max(ans,f(i,j,i1,j1));
                                                  }
                                        }
                              }
                    }
          }
          cout<<ans<<endl;



}


Measured memory_bytes: 256