# -*- coding: utf-8 -*-
from itertools import product
def solve():
    H, W = map(int, input().split())
    M = []
    for i in range(H):
        S = list(int(x=='.') for x in input())
        M.append(S)

    Dist = [[1 if (M[h1][w1] == M[h2][w2] == 1) and (abs(h2-h1)+abs(w2-w1)==1) else float('inf') for h2,w2 in product(range(H), range(W))] for h1,w1 in product(range(H), range(W))]

    for h3,w3 in product(range(H), range(W)):
        for h1,w1 in product(range(H), range(W)):
            for h2,w2 in product(range(H), range(W)):
                Dist[h1*W+w1][h2*W+w2] = min(Dist[h1*W+w1][h2*W+w2], Dist[h1*W+w1][h3*W+w3] + Dist[h3*W+w3][h2*W+w2]);

    return str(max([x for d in Dist for x in d], key = lambda x: int(x) if x < float('inf') else -1))

if __name__ == '__main__':
    print(solve())
