from collections import deque
import itertools
h,w=map(int,input().split())
s=["#"+input()+"#" for i in range(h)]
s.insert(0,'#'*(w+2))
s.append('#'*(w+2))
def dep(s,t,p,q,time):
    print(s)
    s[p][q]=min(time,s[p][q])
    time+=1
    if t[p+1][q]=="." :
        dep(s,t,p+1,q,time)
    if t[p-1][q]=="." :
        dep(s,t,p-1,q,time)
    if t[p][q+1]=="." :
        dep(s,t,p,q+1,time)
    if t[p][q-1]=="." :
        dep(s,t,p,q-1,time)
    return max(itertools.chain.from_iterable(s))

m=0
for i in range(h):
    for j in range(w):
        if s[i+1][j+1]=='.':
            t=[[-1 for l in range(w+2)] for l2 in range(h+2)]
            time=0
            q1=deque([])
            t[i+1][j+1]=time
            q1.appendleft([i+1,j+1])
            while len(q1)!=0:
                q=q1.pop()
                time=t[q[0]][q[1]]+1
                if s[q[0]+1][q[1]]=='.' and t[q[0]][q[1]]==-1:
                    t[q[0]+1][q[1]]=time
                    q1.appendleft([q[0]+1,q[1]])
                if s[q[0] - 1][q[1]] == '.' and t[q[0]-1][q[1]] == -1:
                    t[q[0] - 1][q[1]] = time
                    q1.appendleft([q[0] - 1, q[1]])
                if s[q[0]][q[1]+1] == '.' and t[q[0]][q[1]+1] == -1:
                    t[q[0] ][q[1]+1] = time
                    q1.appendleft([q[0] , q[1]+1])
                if s[q[0]][q[1]-1] == '.' and t[q[0]][q[1]-1] == -1:
                    t[q[0] ][q[1]-1] = time
                    q1.appendleft([q[0], q[1]-1])
            m=max(max(itertools.chain.from_iterable(t)),m)
print(m)