row,col=list(map(int,input().split()))

maze=[list(eval(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):

    if maze[r][c] == '.':

 

      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:

        point = adj_list.pop(0)



        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)



      result.append(point[-1])



print((max(result)))
from collections import deque

H,W = list(map(int,input().split()))

maze = []

for _ in range(H):

  maze.append(list(eval(input())))



res = 0

move = [(1,0),(0,1),(0,-1),(-1,0)]

for i in range(H):

  for j in range(W):

    if maze[i][j] == ".":

      visited = [[False]*W for _ in range(H) ]

      q = deque([(i,j)])

      depth = -1

      while q:

        depth += 1

        L = len(q)

        new = deque([])

        for _ in range(L):

          i,j = q.popleft()

          if visited[i][j]: continue

          visited[i][j] = True

          for y,x in move:

            if 0<=i+y<H and 0<=j+x<W and not visited[i+y][j+x]:

              if maze[i+y][j+x] == ".":

                new.append((i+y,j+x))

        q = new

      res = max(res, depth)



print(res)
row, col = list(map(int, input().split()))
maze = [list(eval(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):
        if maze[r][c] == ".":
            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:
                point = adj_list.pop(0)
                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)
            result.append(point[-1])
print((max(result)))

from collections import deque

H, W = list(map(int, input().split()))
maze = []
for _ in range(H):
    maze.append(list(eval(input())))
res = 0
move = [(1, 0), (0, 1), (0, -1), (-1, 0)]
for i in range(H):
    for j in range(W):
        if maze[i][j] == ".":
            visited = [[False] * W for _ in range(H)]
            q = deque([(i, j)])
            depth = -1
            while q:
                depth += 1
                L = len(q)
                new = deque([])
                for _ in range(L):
                    i, j = q.popleft()
                    if visited[i][j]:
                        continue
                    visited[i][j] = True
                    for y, x in move:
                        if (
                            0 <= i + y < H
                            and 0 <= j + x < W
                            and not visited[i + y][j + x]
                        ):
                            if maze[i + y][j + x] == ".":
                                new.append((i + y, j + x))
                q = new
            res = max(res, depth)
print(res)

-row, col = list(map(int, input().split())) -maze = [list(eval(input())) for _ in range(row)] -result = [] +from collections import deque - -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): -        if maze[r][c] == ".": -            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: -                point = adj_list.pop(0) -                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) -            result.append(point[-1]) -print((max(result))) +H, W = list(map(int, input().split())) +maze = [] +for _ in range(H): +    maze.append(list(eval(input()))) +res = 0 +move = [(1, 0), (0, 1), (0, -1), (-1, 0)] +for i in range(H): +    for j in range(W): +        if maze[i][j] == ".": +            visited = [[False] * W for _ in range(H)] +            q = deque([(i, j)]) +            depth = -1 +            while q: +                depth += 1 +                L = len(q) +                new = deque([]) +                for _ in range(L): +                    i, j = q.popleft() +                    if visited[i][j]: +                        continue +                    visited[i][j] = True +                    for y, x in move: +                        if ( +                            0 <= i + y < H +                            and 0 <= j + x < W +                            and not visited[i + y][j + x] +                        ): +                            if maze[i + y][j + x] == ".": +                                new.append((i + y, j + x)) +                q = new +            res = max(res, depth) +print(res)