from collections import deque
from copy import deepcopy
H, W = map(int, input().split())
maze = [[]for i in range(H)]
for i in range(H):
    S = input()
    for j in range(W):
        maze[i].append(S[j])

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
ans = 0
Q = deque()

for sy in range(H):
    for sx in range(W):
        for gy in range(H):
            for gx in range(W):
                if (sx == gx) and (sy == gy):
                    continue
                if (maze[sy][sx] == '#') or (maze[gy][gx] == '#'):
                    continue
                mazenow = deepcopy(maze)
                Q.clear()
                Q.append((sy, sx))
                mazenow[sy][sx] = 0
                flag = True
                while (len(Q) >= 0) and flag:
                    y, x = Q.popleft()
                    for i in range(4):
                        ny = y + dy[i]
                        nx = x + dx[i]
                        if (ny < 0) or (nx < 0) or (ny >= H) or (nx >= W):
                            continue
                        elif (ny == gy) and (nx == gx):
                            ans = max(ans, mazenow[y][x] + 1)
                            flag = False
                            break
                        elif mazenow[ny][nx] == '.':
                            mazenow[ny][nx] = mazenow[y][x] + 1
                            Q.append((ny, nx))

print(ans)



