from collections import deque
import numpy as np

INF = 10000000000

h, w = map(int, input().split())
s = [] * w

for i in range(h):
    lateral = input()
    s.append(lateral)

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


def bfs(start_x, start_y):
    que = deque()
    d = [[INF for _ in range(w)] for _ in range(h)]
    que.append([start_x, start_y])
    d[start_y][start_x] = 0

    while len(que) > 0:
        p = que.popleft()
        for i in range(4):
            next_x = p[0] + dx[i]
            next_y = p[1] + dy[i]

            if 0 <= next_x < w and 0 <= next_y < h and s[next_y][next_x] != "#" and d[next_y][next_x] == INF:
                que.append([next_x, next_y])
                d[next_y][next_x] = d[p[0]][p[1]] + 1
    print(max(d))
    return max(d)

ans = 0

for y in range(h):
    for x in range(w):
        ans = max(ans, bfs(x, y))

print(ans)