# -*- coding: utf-8 -*-
"""
Created on Sun May  3 19:30:35 2020

@author: Kanaru Sato
"""
import collections as col

h,w = list(map(int, input().split()))
Map = [["*"]*(w+2)]
for i in range(h):
    _ = ["*"] + list(input()) + ["*"]
    Map.append(_)
Map.append(["*"]*(w+2))

"""
for i in range(len(Map)):
    print(Map[i])
""" 

def bfs(start, goal):
    #print("bfs",start,goal)
    around = [[1,0],[0,1],[-1,0],[0,-1]]
    
    dic = {}
    dic[tuple(start)] = 0
    
    q = col.deque([start])
    
    while tuple(goal) not in dic:
        #print("queue is",q)
        now = q.popleft()
        for dif in around:
            np = [now[0]+dif[0],now[1]+dif[1]]
            if tuple(np) not in dic:
                if Map[np[0]][np[1]] == ".":
                    dic[tuple(np)] = dic[tuple(now)]+1
                    q.append(np)
                else:
                    dic[tuple(np)] = "no"
    return dic[tuple(goal)]

Maxlength = -1

for start0 in range(1,h):
    for start1 in range(1,w):
        for goal0 in range(start0+1,h+1):
            for goal1 in range(start1+1,w+1):
                start = [start0, start1]
                goal = [goal0, goal1]
                if Map[start0][start1] == "." and Map[goal0][goal1] == ".":
                    length = bfs([start0,start1],[goal0,goal1])
                    if Maxlength < length:
                        Maxlength = length

print(Maxlength)