row,col=map(int,input().split())
maze=[list(input()) for _ in range(row)]
result = []
 
def create_next_adj_list(point):
  cur_x, cur_y, cur_depth = point
  return [(cur_x, cur_y+1, cur_depth+1), (cur_x+1, cur_y, cur_depth+1), (cur_x, cur_y-1, cur_depth+1), (cur_x-1, cur_y, cur_depth+1)]
 
for r in range(row):
  for c in range(col):
 
    visited = [ [0]*col for _ in range(row)]
    visited[r][c] = -1
 
    adj_list = [(r, c+1, 0), (r+1, c, 0), (r, c-1, 0), (r-1, c, 0)]
 
    while adj_list:
    # for p in range(len(adj_list)):
      max_depth = 0
      point = adj_list.pop(0)
      print(point)

      if 0<=point[0]<row and 0<=point[1]<col and visited[point[0]][point[1]] != -1:
        visited[point[0]][point[1]] = -1
        if maze[point[0]][point[1]] != '#':
          for adj in create_next_adj_list(point):
            adj_list.append(adj)
          if point[-1] > max_depth:
            max_depth = point[-1]

      result.append(max_depth)

print(max(result))