from collections import deque

h,w=map(int,input().split())
S=[input() for _ in range(h)]
inf=float("inf")
ans=0

for i in range(h):
    for j in range(w):
        dist=[[inf for _ in range(w)] for _ in range(h)]
        dist[i][j]=0
        que=deque([(i,j)])
        while que:
            si,sj=que.popleft()
            for ni,nj in [(si+1,sj),(si-1,sj),(si,sj+1),(si,sj-1)]:
                if 0<=ni<=h-1 and 0<=nj<=w-1 and S[ni][nj]!="#":
                    if dist[ni][nj]>dist[si][sj]+1:
                        dist[ni][nj]=dist[si][sj]+1
                        ans=max(ans,dist[si][sj]+1)
                        que.append((ni,nj))

print(ans)