from collections import deque
H, W = map(int, input().split())
sheet = [[0]*(W+2) for i in range(H+2)]
for i in range(H):
  s = input()
  for j in range(W):
    if s[j]=='.':
      sheet[i+1][j+1] = 1

m = -1
for i in range(1, H+1):
  for j in range(1, W+1):
    for a in range(1, H+1):
      for b in range(1, W+1):
        if sheet[i][j]==0 or sheet[a][b]==0:
          continue
        stuck = deque([(j, i, 0)])
        while stuck:
          x, y, c = stuck.popleft()
          if x==b and y==a:
            if m<c:
              m=c
            break
          for dx, dy in [(0,1), (0,-1), (1,0), (-1,0)]:
              if sheet[y+dy][x+dx]==1:
                stuck += [(x+dx, y+dy, c+1)]
print(m)