import Queue
import copy

H, W = map(int, raw_input().split())
S = []

for i in range(H):
    S.append(list(raw_input()))


def bfs(start, goal, S2):
    q = Queue.Queue()
    q.put(start)
    candidates = [[0, 1], [1, 0], [0, -1], [-1, 0]]
    dist = [[0]*W for _ in range(H)]
    while not q.empty():
        i = q.get()
        x = i[0]
        y = i[1]
        S2[x][y] = "#"

        for candi in candidates:
            x_new = x + candi[0]
            y_new = y + candi[1]

            if x_new < H and x_new >= 0:
                if y_new < W and y_new >=0:
                    if S2[x_new][y_new] == ".":
                        dist[x_new][y_new] = dist[x][y] + 1
                        q.put([x_new, y_new])

    return dist[goal[0]][goal[1]]


ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            for k in range(H):
                for l in range(W):
                    S2 = copy.deepcopy(S)
                    ans = max(ans, bfs([i, j], [k, l], S2))

print ans

