import sys
input = sys.stdin.readline
h, w = [int(x) for x in input().strip().split()]
m = [[0 for _ in range(w)] for _ in range(h)]
for hi in range(h):
    for wi, s in enumerate(input().strip()):
        m[hi][wi] = s

c = [[float('inf')] * (h*w) for _ in range(h*w)]
for i in range(h*w):
    c[i][i] = 0

for hi in range(h):
    for wi in range(w):
        #print(hi, wi)
        if m[hi][wi] == '#':
            continue
        for offset in [(0, 1), (-1, 0), (0, -1), (1, 0)]:
            if hi+offset[0] < 0 or hi+offset[0] == h:
                continue
            if wi+offset[1] < 0 or wi+offset[1] == w:
                continue
            if m[hi+offset[0]][wi+offset[1]] == '#':
                continue
            #print('offset = {}'.format(offset))
            #print('hi*w+wi = {}'.format(hi*w+wi), '(hi+offset[0])*w+(wi+offset[1]) = {}'.format((hi+offset[0])*w+(wi+offset[1])))
            c[hi*w+wi][(hi+offset[0])*w+(wi+offset[1])] = 1

#print('-- cost --')
#for ci in c:
#    print(ci)

for k in range(h*w):
    for i in range(h*w):
        for j in range(h*w):
            c[i][j] = min(c[i][j], c[i][k]+c[k][j])

ans = 0
#print('-- total cost --')
#for ci in c:
#    print(ci)

for ci in c:
    for cii in ci:
        if cii != 0 and cii != float('inf'):
            ans = max(ans, cii)

print(ans)