import networkx as nx

H, W = map(int, input().split())
S = [input() for i in range(H)]

G = nx.Graph()
for i in range(len(S)):
    for j in range(len(S[i])):
        if S[i][j] == '.':
            G.add_node((i,j))

for i in list(G.nodes):
    if G.has_node((i[0],i[1]+1)):
        G.add_edge(i, (i[0], i[1]+1))
    if G.has_node((i[0]+1,i[1])):
        G.add_edge(i, (i[0]+1, i[1]))

maxpath = 0
nodes = list(G.nodes)
for i in range(len(nodes)-1):
    for j in range(i+1, len(nodes)):
        l = len(nx.shortest_path(G, source=nodes[i], target=nodes[j]))
        maxpath = max(l, maxpath)

print(maxpath - 1)
