from collections import deque
h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(list(input()))

def cal_dist(sx, sy):
    # スタートからの距離を格納
    x_max, y_max = h, w
    dist = [[float('inf')] * w for _ in range(h)]

    # キューを作成
    que = deque([])
    que.append((sx, sy))
    dist[sx][sy] = 0

    # ゴールにたどり着くまで探索
    dist_max = 0
    while len(que) > 0:
        x, y = que.popleft()
        # if x == gx and y == gy:
        #     break

        dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]
        for i in range(0, 4):
            nx, ny = x + dx[i], y + dy[i]
            if 0 <= nx < x_max and 0 <= ny < y_max and \
               s[nx][ny] != '#' and dist[nx][ny] == float('inf'):
                que.append((nx, ny))
                dist[nx][ny] = dist[x][y] + 1
                dist_max = max(dist[nx][ny], dist_max)

    return dist_max

dist_max = 0
for i in range(h):
    for j in range(w):
        dist = cal_dist(i, j)
        if dist == float('inf'):
            continue
        dist_max = max(dist, dist_max)
print(dist_max)