import queue

q = queue.Queue()

H,W = map(int,input().split())
S = [list(input()) for i in range(H)]
ans = 0
vec_x = [1,0,-1,0]
vec_y = [0,1,0,-1]

def bfs(sx,sy):
    #最短距離を格納する配列
    d = [[0 for i in range(W)] for j in range(H)]
    q.put([sx,sy])
    while not q.empty():
        current_xy = q.get()
        #4方向のループ
        for i in range(4):
            nx = current_xy[0] + vec_x[i]
            ny = current_xy[1] + vec_y[i]

            #移動が可能か
            if( (nx >= 0 and nx < W ) and (ny >= 0 and ny < H ) ):
                if S[ny][nx] != "#":
                    #すでにおとずれていないか
                    if d[ny][nx] == 0:
                        q.put([nx,ny])
                        d[ny][nx] = d[current_xy[1]][current_xy[0]] + 1
    return d[current_xy[1]][current_xy[0]]

for sx in range(W):
    for sy in range(H):
        if S[sy][sx] == "#":
            continue
        if ans <= bfs(sx,sy):
            ans = bfs(sx,sy)

print(ans)