import sys
from collections import deque
import fractions
from functools import reduce
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

from collections import deque


def bfs(sx, sy, gx, gy, H, W):
    d = [[-1 for i in range(W)] for j in range(H)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((sy, sx))
    d[sy][sx] = 0

    while que:
        p = que.popleft()
        if p[0] == gy and p[1] == gx:
            break
        for i in range(4):
            ny = p[0] + dy[i]
            nx = p[1] + dx[i]
            #print(nx, ny)
            if 0 <= nx < W and 0 <= ny < H and maze[ny][nx] != "#" and d[ny][nx] == -1:
                que.append((ny, nx))
                #print(p[0], p[1], ny, nx)
                d[ny][nx] = d[p[0]][p[1]] + 1
    return d[gy][gx]


H, W = na()
ans = 0
maze = [input() for i in range(H)]
for sy in range(H):
    for sx in range(W):
        if maze[sy][sx] == '#':
            continue
        for gy in range(H):
            for gx in range(W):
                if maze[gy][gx] == '#':
                    continue
                #print(sx, sy, gx, gy)
                ans = max(ans, bfs(sx, sy, gx, gy, H, W))
                #print(ans)
print(ans)
