ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

h,w = mi()

st = [['#'] * (w+2) for i in range(h+2)]
for i in range(h):
    l = input()
    for j in range(w):
        st[i+1][j+1] = l[j]


ans = 0

from collections import deque
from itertools import chain
for i in range(1,h+1):
    for j in range(1,w+1):
        if st[i][j] == '.':
            ex = [[0] * (w+2) for i in range(h+2)]
            ex[i][j] = 1

            l = deque()
            l.append((i,j))

            while len(l) != 0:
                x,y = l.popleft()
                step = ex[x][y]
                for xx,yy in [(x-1,y),(x,y-1), (x+1,y),(x,y+1)]:
                    if st[xx][yy] == '.' and ex[xx][yy] == 0:
                        l.append((xx,yy))
                        ex[xx][yy] = step+1
        ans = max(ans, step-1)
print(ans)