from collections import deque

dis_x = [1, 0, -1, 0]
dis_y = [0, 1, 0, -1]

h, w = map(int, input().split())
s = ["#{}#".format(input()) for _ in range(h)]
h += 2
w += 2

s = ["#" * w] + s + ["#" * w]

# 最終的な最大値
res_opt = -2

# 各ループ開始
for h_i in range(h):
  for w_i in range(w):
    if s[h_i][w_i] != '#':
      # BFS開始
      visited = [ [-1] * w for _ in range(h) ]
      visited[h_i][w_i] = 0
      queue = deque([(h_i, w_i)])
      
      while queue:
        x, y = queue.popleft()
        
        # 上下4マスに対して
        opt = 0
        for i in range(4):
          
          dx, dy = dis_x[i], dis_y[i]
          if s[x+dx][y+dy] == '.' and visited[x+dx][y+dy] == -1:
            visited[x+dx][y+dy] = visited[x][y] + 1
            opt += visited[x+dx][y+dy]
            queue.append((x+dx, y+dy))
        res_opt = max(res_opt, opt)

print(res_opt)