#!/usr/bin/env python3
def main():
    from collections import deque
    from itertools import product

    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]

    h_indexes = [x for x in range(H)]
    w_indexes = [x for x in range(W)]
    move = ((0, 1), (0, -1), (1, 0), (-1, 0))
    ans = 0
    for sh, gh in product(h_indexes, repeat=2):
        for sw, gw in product(w_indexes, repeat=2):
            if S[sh][sw] == '#' or S[gh][gw] == '#':
                continue
            queue = deque([(sh, sw)])
            distance = [[0] * W for _ in range(H)]
            while queue:
                h, w = queue.popleft()
                if h == gh and w == gw:
                    break
                for dh, dw in move:
                    nh = h + dh
                    nw = w + dw
                    if (1
                            and 0 <= nh < H
                            and 0 <= nw < W
                            and S[nh][nw] == '.'
                            and distance[nh][nw] == 0):
                        distance[nh][nw] = distance[h][w] + 1
                        queue.append((nh, nw))
            if ans < distance[gh][gw]:
                ans = distance[gh][gw]
    print(ans)


if __name__ == '__main__':
    main()
