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))

Maxlist = []
ans = [0]

def numap(i,j,m,add=True):
    que = [[i,j]]
    count = 0
    while que:
        newque = []
        for q in que:
            frag = 0#4になると極大値
            x=q[0]
            y=q[1]
            m[x][y]=count
            if m[x+1][y]=='.':
                newque.append([x+1,y])
            else:
                frag+=1
            if m[x-1][y]=='.':
                newque.append([x-1,y])
            else:
                frag+=1
            if m[x][y-1]=='.':
                newque.append([x,y-1])
            else:
                frag+=1
            if m[x][y+1]=='.':
                newque.append([x,y+1])
            else:
                frag+=1
            if frag == 4 and add:
                Maxlist.append([x,y])
        que = newque
        count+=1
    ans[0] = max(ans[0],count-1)

# i行j列 という指定の仕方になる
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

for l in Maxlist:
    mp = copy.deepcopy(m)
    numap(l[0],l[1],mp,add=False)

print(ans[0])