# -*- coding: utf-8 -*-
H, W = map(int, input().split(' '))
table = [[c for c in input()] for _ in range(H)]

def dfs(i, j):
    dists = [[-1 for _ in range(W)] for _ in range(H)]
    nexts = ((-1,0), (1,0), (0,-1), (0,1))

    buf = [(i, j)]
    dists[i][j] = 0
    while buf:
        i, j = buf.pop(0)

        for x, y in nexts:
            next_i = i + x
            next_j = j + y
            if 0 <= next_i < H and 0 <= next_j < W:
                if table[next_i][next_j] == '.' and dists[next_i][next_j] == -1:
                    dists[next_i][next_j] = dists[i][j] + 1
                    buf.append((next_i, next_j))




    # for d in dists:
    #     print(d)

    return max(max(dists))

# print(table)

ans = 0
for i in range(H):
    for j in range(W):
        if table[i][j] == '.':
            n = dfs(i, j)
            ans = max(ans, n)


print(ans)