import collections
h,w = map(int, input().split())
s=[input()for _ in range(h)]
r=[[1,0],[-1,0],[0,1],[0,-1]]
def bfs(i,j):
    global h,w,r
    f=[-1 for _ in range(h*w)]
    que = [[] for _ in range(h*w)]
    que[0].append([i,j])
    for k in range(h*w):
        if que[k]:
            res = k
            for i,j in que[k]:
                f[i*w+j] =k
                for sr in r:
                    ti = i + sr[0]
                    tj = j + sr[1]
                    if ti>=0 and tj>=0 and ti<h and tj<w:
                        if s[ti][tj] == ".":
                            if f[ti*w+tj] == -1:
                                que[k+1].append([ti,tj])
    return res

res = 0
for i in range(h):
    for j in range(w):
        if s[i][j] ==".":
            res = max(res,bfs(i,j))
print(res)