import queue
r,c=map(int,input().split())
ko =[list(input()) for i in range(r)]

ans = 0
for sy in range(r):
    for sx in range(c):
        for gy in range(r):
            for gx in range(c):
                if ko[sy][sx] == "." and ko[gy][gx] == ".":
                    a = [[0 for i in range(c)] for i in range(r)]
                    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 ko[sy+i[0]][sx+i[1]]==".":
                            a[sy+i[0]][sx+i[1]]=1
                            q.put((sy+i[0],sx+i[1]))

                    while True:
                        y,x=q.get()
                        if y==gy and x==gx:
                            break
                        for i in d:
                            if 0<=y+i[0]< r and 0<=x+i[1]< c and ko[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("出発地", sx, sy, "到着地", gx, gy,a[gy][gx])
                    if a[gy][gx] > ans:
                        ans = a[gy][gx]

print(ans)