# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque
from operator import itemgetter
from heapq import heappop, heappush
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
H, W = inpl()
G = [[1]*(W+2)]
for _ in range(H):
    G.append([1] + [int(s=="#") for s in input()] + [1])
G.append([1]*(W+2))

ans = 0
for h in range(1, H+1):
    for w in range(1, W+1):
        dist = [[-1]*(W+2) for _ in range(H+2)]
        dist[h][w] = 0
        Q = deque()
        Q.append([h, w])
        while Q:
            ph, pw = Q.popleft()
            for dh, dw in [[0, 1], [1, 0], [-1, 0], [0, -1]]:
                qh, qw = ph+dh, pw + dw
                if G[qh][qw]:
                    continue
                if dist[qh][qw] == -1:
                    dist[qh][qw] = dist[ph][pw] + 1
                    Q.append([qh, qw])
                
        for y in range(1, H+1):
            for x in range(1, W+1):
                ans = max(ans, dist[y][x])
print(ans)