from itertools import combinations
import copy

h, w = map(int, input().split())

maze = [list("#"+input()+"#") for _ in range(h)]
res = [i for i in "#"*(w+2)]
maze.insert(0, res)
maze.append(res)




p = []
for y, l in enumerate(maze):
    for x, m in enumerate(l):
        if m == ".":
            p.append([y, x])


ans = []

for c in combinations(p, 2):
    sy, sx = c[0][0], c[0][1]
    gy, gx = c[1][0], c[1][1]

    temp_maze = copy.deepcopy(maze)
    temp_maze[sy][sx] = 0

    loc = [[sy, sx]]

    for k in range(1, (h+2)*(w+2)):
        next_loc = []
        for y, x in loc:
            for i, j in ([1,0], [-1,0], [0,1],[0,-1]):
                    if temp_maze[y+i][x+j] == '.':
                        temp_maze[y+i][x+j] = k
                        next_loc.append([y+i, x+j])
        loc = next_loc
        if [gy, gx] in loc:
            ans.append(k)
            

print(max(ans))