import copy

H,W = map(int,input().split())

field = [["."]*W for _ in range(H)]

for i in range(H):
    input2 = input()
    for j in range(W):
        field[i][j] = input2[j]

dist = 0

for a in range(H):
    for b in range(W):

        field_test = copy.deepcopy(field)

        if field_test[a][b] == ".":
            field_test[a][b] = 0
            
            for k in range(H * W):
                for i in range(H):
                    for j in range(W):
                         if field_test[i][j] == k:
                            try:
                                if 0 <= i + 1 <= H and 0 <= j <= W:
                                    if field_test[i + 1][j] == ".":
                                        field_test[i + 1][j] = k + 1
                                        dist = max(dist,k + 1)
                            except:
                                pass
                    
                            try:
                                if 0 <= i - 1 <= H and 0 <= j <= W:
                                    if field_test[i - 1][j] == ".":
                                        field_test[i - 1][j] = k + 1
                                        dist = max(dist,k + 1)
                            except:
                                pass
                    
                            try:
                                if 0 <= i <= H and 0 <= j + 1 <= W:
                                    if field_test[i][j + 1] == ".":
                                        field_test[i][j + 1] = k + 1
                                        dist = max(dist,k + 1)
                            except:
                                pass
                            
                            try:
                                if 0 <= i <= H and 0 <= j - 1 <= W:
                                    if field_test[i][j - 1] == ".":
                                        field_test[i][j - 1] = k + 1
                                        dist = max(dist,k + 1)
                            except:
                                pass


print(dist)