from collections import deque

h, w = map(int, input().split())
S = [['#']*(w+2)]

for _ in range(h):
    s = str(input())
    new_s = ['#']
    for x in s:
        new_s.append(x)
    new_s.append('#')
    S.append(new_s)
S.append(['#']*(w+2))

Possible_list = []
for i in range(h+2):
    for j in range(w+2):
        if S[i][j] == '.':
            Possible_list.append((i,j))

max_length = 0

for zahyou in Possible_list:
    dq = deque()
    Visited = [-1 for _ in range(len(Possible_list))]
    Visited[Possible_list.index(zahyou)] = 0
    dq.append(zahyou)
    
    while dq:
        now = dq.popleft()
        
        Adj_possible = []
        if (now[0]-1, now[1]) in Possible_list:
            Adj_possible.append((now[0]-1, now[1]))
        if (now[0]+1, now[1]) in Possible_list:
            Adj_possible.append((now[0]+1, now[1]))
        if (now[0], now[1]-1) in Possible_list:
            Adj_possible.append((now[0], now[1]-1))
        if (now[0], now[1]+1) in Possible_list:
            Adj_possible.append((now[0], now[1]+1))
        
        for next_zahyou in Adj_possible:
            if Visited[Possible_list.index(next_zahyou)] != -1:
                continue
            Visited[Possible_list.index(next_zahyou)] = Visited[Possible_list.index(now)] + 1
            dq.append(next_zahyou)
    
    max_length = max(max_length, max(Visited))

print(max_length)