H, W = map(int, input().split())
maze = []
for i in range(H):
    maze.append(list(input()))
    
from collections import deque
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
# 最大の地点を
def dfs(sx, sy, gx, gy):
    que = deque()
    # 各点までの最長距離の配列
    d = [[-1 for _ in range(W)] for _ in range(H)]
    que.append([sx, sy])
    d[sx][sy] = 0
    
    while(len(que) != 0):
        front = que.popleft()
        if (front[0] == gx and front[1] == gy):
            break
        for i in range(4):
            nx = front[0] + dx[i]
            ny = front[1] + dy[i]
            if (0 <= nx and nx < H and 0 <= ny and ny < W):
                if maze[nx][ny] != "#" and d[nx][ny] == -1:
                    que.append([nx, ny])
                    d[nx][ny] = d[front[0]][front[1]] + 1
                else:
                    continue
            else:
                continue
    return d[gx][gy]

import itertools

ans = []
l1 = [(s1, s2) for s1 in range(H) for s2 in range(W)]
p = itertools.product(l1, l1)

for v in p:
    if maze[v[0][0]][v[0][1]] == "#" or maze[v[1][0]][v[1][1]] == "#":
        continue
    ans.append(dfs(v[0][0], v[0][1], v[1][0], v[1][1]))
print(max(ans))