import sys
import copy

sys.setrecursionlimit(200000)

def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))



H,W=two_int()
maps = [[0 for i in range(W)] for j in range(H)]
not_wall_dicts = []

for i in range(H):
    S = one_str()
    for index,j in enumerate(S):
        if j =="#":
            maps[i][index] = 1
        else:
            not_wall_dicts.append([index,i])

def dfs2(pos, root, goal):
    # 停止条件
    # 深さに限らず，任意の停止条件を書く
    x,y = pos[0],pos[1]
    pos_str = str(pos[0])+"_"+str(pos[1])

    if pos_str in root or maps[y][x]==1:
        return 1000
    if pos_str==goal_str:
        return len(root)
        
    root[pos_str] = 1

    ret1,ret2,ret3,ret4 = 1000,1000,1000,1000
    if x >= 1:
        ret1 = dfs2([x-1, y], copy.deepcopy(root),goal_str)
    
    if x < W-1:
        ret2 = dfs2([x+1, y], copy.deepcopy(root),goal_str)

    if y >= 1:
        ret3 = dfs2([x, y-1], copy.deepcopy(root),goal_str)

    if y < H-1:
        ret4 = dfs2([x, y+1], copy.deepcopy(root),goal_str)

    return min(ret1, ret2, ret3, ret4)



length = len(not_wall_dicts)
maxs = 0
for i in range(length-1):
    goal = not_wall_dicts[i]
    goal_str = str(goal[0])+"_"+str(goal[1])
    for j in range(i,length):
        temp = dfs2(not_wall_dicts[j], {}, goal_str)
        
        if temp > maxs:
#             print(temp, not_wall_dicts[j], not_wall_dicts[i])
            maxs = temp

print(maxs)

