#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
import queue
import numpy as np

def sol(h,w,s,start):
    dx = [1, 0, -1, 0]
    dy=[0,1,0,-1]
    inf = -1000000000
    d=np.array([[inf for i in range(w)] for i in range(h)])
    q=queue.Queue()
    q.put(start)
    d[start[1]][start[0]]=0
    while not q.empty():
        p = q.get()
        for i in range(4):
            nx=p[0]+dx[i]
            ny=p[1]+dy[i]
            if 0<=nx<w and 0<=ny<h:
                S = s[ny][0]
                if d[nx][ny]==inf:
                    
                    if S[nx]=='.':
                        q.put([nx,ny])
                        d[nx][ny]=d[p[0]][p[1]]+1
    return np.max(d)


def main():
    import sys
    input = sys.stdin.readline
    h,w = map(int, input().split())
    s = []
    for i in range(h):
        SS = list(map(str, input().split()))
        s.append(SS)
    ans=[]
    for i in range(w):
        for j in range(h):
            start = [i,j]
            ans.append(sol(h,w,s,start))
    print(max(ans))
        


if __name__ == "__main__":
    main()
