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):
            if S[s_y][s_x] == '.':
                dist_max = 0
                dist_max_pos = (s_y, s_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))
                                    dist_max = max(dist_max, dist[y][x] + 1)
                                    dist_max_pos = (n_y, n_x)
                cost_max = max(cost_max, dist[dist_max_pos[0]][dist_max_pos[1]])

print(cost_max)