import copy

h,w = [int(i) for i in input().split()]
m = [list(input()) for i in range(h)]
for l in m:
    l.insert(0,'#')
    l.append('#')
m.insert(0,['#']*(w+2))
m.append(['#']*(w+2))

x = 0
y = 0
ans = 0

def numap(i,j,m):
    global x
    global y
    global ans
    que = [[i,j]]
    count = 0
    while que:
        newque = []
        for q in que:
            if m[q[0]][q[1]]=='.':
                x=q[0]
                y=q[1]
                m[x][y]=count
                newque.append([x+1,y])
                newque.append([x,y+1])
                newque.append([x-1,y])
                newque.append([x,y-1])
        que = newque
        count+=1
    ans = max(ans,count-2)

while True:
    flag = 0
    mp = copy.deepcopy(m)
    breakflag = False
    for i,a in enumerate(mp):
        for j,b in enumerate(a):
            if b == '.':
                numap(i,j,mp)
                breakflag = True
                break
        if breakflag:
            break
    if breakflag == False:
        break
    numap(x,y,m)

print(ans)