from queue import Queue
from itertools import product
import numpy as np

NOT_VISITED = 0
SCHEDULED = 1
VISITED = 2

H, W = map(int, input().split())
S = np.zeros((H, W), dtype='U1')
for hi in range(H):
    raw = input()
    S[hi, :] = list(raw)

maxmove = np.zeros_like(S, dtype='int')

for hi, wi in product(range(H), range(W)):
    # hi, wiをスタート位置とする場合
    if S[hi, wi] == '#': continue

    # 必要な諸々を定義
    flag = np.zeros_like(S, dtype='int')
    flag[:] = NOT_VISITED
    flag[hi, wi] = VISITED
    nummove = np.zeros_like(S, dtype='int')
    queue = Queue()

    queue.put((hi, wi))
    while queue.empty() == False:
        hj, wj = queue.get()
        flag[hj, wj] = VISITED
        for neighbour in [(hj, wj-1), (hj, wj+1), (hj+1, wj), (hj-1, wj)]:
            if not (0 <= neighbour[0] < H and 0 <= neighbour[1] < W): continue
            if S[neighbour] == '#': continue
            if flag[neighbour] == NOT_VISITED:
                nummove[neighbour] = nummove[hj, wj] + 1
                queue.put(neighbour)
                flag[neighbour] = SCHEDULED
    
    maxmove[hi, wi] = np.max(nummove)

print(np.max(maxmove))
