from collections import namedtuple
from queue import Queue
from copy import deepcopy

def bfs(start, stage):
    if stage[start.y][start.x] == "#":
        return -1
    ans = 0
    q = Queue()
    q.put(start)
    stage[start.y][start.x] = 0
    while not q.empty():
        current = q.get()
        for move in moves:
            nxt = point(current.y + move.y, current.x + move.x)
            can_move = 0 <= nxt.y < h and 0 <= nxt.x < w and stage[nxt.y][nxt.x] == "."
            if can_move:
                q.put(nxt)
                stage[nxt.y][nxt.x] = stage[current.y][current.x] + 1
                ans = stage[current.y][current.x] + 1
    return ans


point = namedtuple("point", "y, x")
moves = [point(-1, 0), point(0, 1), point(1, 0), point(0, -1)]
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
ans = -1
for y in range(h):
    for x in range(w):
        steps = bfs(point(y, x), deepcopy(S))
        ans = max(ans, steps)
print(ans)
