from collections import deque
h,w = map(int,input().split())
s = [input() for _ in range(h)]
ans=0
for i in range(h):
  for j in range(w):
    if s[i][j] =='#':
      continue
    visited=[[-1]*w for _ in range(h)]
    visited[i][j] = 0
    cnt=0
    q = deque([[i,j]])
    while q:
      x,y = q.popleft()
      for k,l in [[0,-1],[0,1],[1,0],[-1,0]]:
        nx,ny = k+x,l+y
        if nx<0 or ny<0 or nx>=h or ny>=w:
          continue
        if s[nx][ny]=='.' and visited[nx][ny]==-1:
          visited[nx][ny] = visited[x][y] + 1
          q.append([nx,ny])
          ans = max(ans,visited[nx][ny])
print(ans)