import queue
r,c=map(int,input().split())
#sy,sx=map(int,input().split())
#gy,gx=map(int,input().split())
a=[list(input()) for i in range(r)]
sy,sx = (1,1)
#gy,gx = (2,2)
def minload(sy,sx,a):
    sy-=1
    sx-=1
    #gy-=1
    #gx-=1
    q = queue.Queue()
    d=[(-1,0),(1,0),(0,-1),(0,1)]
    a[sy][sx]=0
    for i in d:
        if 0<=sy+i[0]<r and 0<=sx+i[1]<c and a[sy+i[0]][sx+i[1]]==".":
            a[sy+i[0]][sx+i[1]]=1
            q.put((sy+i[0],sx+i[1]))
    while True:
        if queue.Queue.empty(q):
            break
        y,x=q.get()
        #if y==r and x==c:
            #break
        for i in d:
            if 0<=y+i[0]<r and 0<=x+i[1]<c and a[y+i[0]][x+i[1]]==".":
                a[y+i[0]][x+i[1]]=a[y][x]+1
                q.put((y+i[0],x+i[1]))
    #print(a[gy][gx])
    max = 0
    for i in a:
        for j in i:
            if j != '#' and j !='.':
                if j > max:
                    max = j
    return(max)
ans = 0
for sy in range(1,r+1): 
    for sx in range(1,c+1):
        b = []
        for i in a:
            b.append(list(i))
        if a[sy-1][sx-1]==".":
            local_max = minload(sy,sx,b)
            #print(local_max)
            #print(b)
        if local_max > ans:
            ans = local_max
print(ans)