#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

h,w=map(int,input().split())
d=[]
for i in range(h):
    s=input()
    d.append(s)
#p={}
x=h*w
p=[[500]*x for i in range(x)]
for i in range(x):
    for j in range(x):
        ih,iw=i//w,i%w
        jh,jw=j//w,j%w
        if "."==d[ih][iw]==d[jh][jw] and ih==jh and abs(iw-jw)==1:
            p[i][j]=1
            p[j][i]=1
        if "."==d[ih][iw]==d[jh][jw] and iw==jw and abs(ih-jh)==1:
            p[i][j]=1
            p[j][i]=1
for i in range(x):
    for j in range(x):
        for k in range(x):
            ih,iw=i//w,i%w
            jh,jw=j//w,j%w
            kh,kw=k//w,k%w
            p[j][k]=min(p[j][k],p[j][i]+p[i][k])
ans=0
for i in p:
    for j in i:
        if j!=500:
            ans=max(ans,j)
print(ans)
