from collections import deque
h,w=map(int,input().split())
S=[input() for _ in range(h)]

ans=0
dxy=[(0,1),(1,0),(0,-1),(-1,0)]
for x in range(w):
  for y in range(h):
    if S[y][x]=='#': continue
    q=deque([(x,y,0)])
    memo=[[-1]*w for _ in range(h)]
    memo[y][x]=0
    while q:
      x,y,cnt=q.popleft()
      cnt+=1
      for dx,dy in dxy:
        nx,ny=x+dx,y+dy
        if not 0<=nx<w: continue
        if not 0<=ny<h: continue
        if S[ny][nx]=='#':continue
        if memo[ny][nx]<0:
          memo[ny][nx]=cnt
          q.append([nx,ny,cnt])
    ans=max(ans,max(max(memo)))
print(ans)