from collections import deque
import math

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

cost_max = 0
for s_y in range(H):
    for s_x in range(W):
        for g_y in range(H):
            for g_x in range(W):
                if s_y != g_y or s_x != g_x:
                    if S[s_y][s_x] == '.' and S[g_y][g_x] == '.':
                        dist = [[math.inf] * W for i in range(H)]
                        queue = deque([(s_y, s_x)])
                        dist[s_y][s_x] = 0
                        while queue:
                            y, x = queue.popleft()
                            for i, j in [(1,0),(0,1),(-1,0),(0,-1)]:
                                n_x, n_y = x + i, y + j
                                if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
                                    if dist[n_y][n_x] > dist[y][x]:
                                        if S[n_y][n_x] == '.':
                                            dist[n_y][n_x] = dist[y][x] + 1
                                            queue.append((n_y, n_x))
                        cost_max = max(cost_max, dist[g_y][g_x])

print(cost_max)