import collections as cl

def func (h,w,i,j):
    count=0
    ans=[1]
    q=cl.deque()
    q.append([i,j,count])
    ch=[[0 for i in range(w)]for j in range(h)]
    while q:
        i,j,count=q.popleft()
        if i-1>=0 and s[i-1][j]=='.' and ch[i-1][j] == 0:
            q.append([i-1,j,count+1])
            ch[i-1][j] = 1
            ans.append(count+1)
        if i+1 < h and s[i+1][j] == '.' and ch[i+1][j] == 0:
            q.append([i+1,j,count+1])
            ch[i+1][j] = 1
            ans.append(count+1)
        if j-1 >= 0 and s[i][j-1] == '.' and ch[i][j-1] == 0:
            q.append([i,j-1,count+1])
            ch[i][j-1] = 1
            ans.append(count+1)
        if j+1 < w and s[i][j+1] == '.' and ch[i][j+1] == 0:
            q.append([i,j+1,count+1])
            ch[i][j+1] = 1
            ans.append(count+1)

    return max(ans)

h,w=map(int,input().split())
s=[]
ans=[]
for i in range(h):
    s.append(list(map(str,input())))

for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            ans.append(func(h,w,i,j))
        else:
            continue
print(max(ans))
