h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
p = [(0,1),(1,0),(-1,0),(0,-1)]
mx = 0
for i in range(h):
    for j in range(w):
        corse = {}
        start = (i,j)
        n1 ={start}
        cnt = 1
        while n1 != set():
            n2 = set()
            for k in n1:
                for l in p:
                    nk = (k[0]+l[0],k[1]+l[1])
                    if 0<=nk[0]<h and 0<=nk[1]<w:
                     if s[nk[0]][nk[1]] != '#' and corse.get(nk) == None:
                        corse[nk] = 1
                        mx = max(cnt,mx)
                        n2.add(nk)
            cnt += 1
            n1 = n2
print(mx)
