import queue
import numpy as np

H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]
dir4 = [[-1,0],[1,0],[0,-1],[0,1]]


def solveMaze(s, g):
    q = queue.Queue()
    q.put([s[0],s[1],0])
    times = [[999999999 for j in range(W)] for i in range(H)]

    while not q.empty():
        now = q.get()
        for i in range(4):
            nextH = now[0] + int(dir4[i][0])
            nextW = now[1] + int(dir4[i][1])
            time = now[2] + 1
            g0 = g[0]
            g1 = g[1]

            if nextH == g[0] and nextW == g[1]:
                return time

            if nextH < 0 or nextH >= H or nextW < 0 or nextW >=W or maze[nextH][nextW] == "#" or times[nextH][nextW] <= time:
                continue
            else:
                times[nextH][nextW] = time
                q.put([nextH, nextW, time])

    return -1


ans = 0

for sH in range(H):
    for sW in range(W):
        if maze[sH][sW] == ".":
            for gH in range(H):
                for gW in range(W):
                    if maze[gH][gW] == ".":
                        if sH != gH or sW != gW:
                            ans = max(ans, solveMaze([sH, sW], [gH, gW]))

print(ans)





