from collections import deque
ddx = [0, 0, -1, 1]
ddy = [-1, 1, 0, 0]

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

res = 0
inf = 9999999
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            continue
        dist = [[inf]*w for _ in range(h)]
        dist[i][j] = 0
        que = deque([[i, j]])
        while len(que):
            y, x = que.popleft()
            for dx, dy in zip(ddx, ddy):
                if x+dx < 0 or x+dx >= w or y+dy < 0 or y+dy >= h or s[y+dy][x+dx] == '#' or dist[y+dy][x+dx] < inf:
                    continue
                que.append([y+dy, x+dx])
                dist[y+dy][x+dx] = dist[y][x] + 1
        ma = 0
        for i in range(h):
            for j in range(w):
                if dist[i][j] < inf:
                    ma = max(ma, dist[i][j])
        res = max(ma, res)
print(res)

