import sys

import numpy as np

from collections import deque



h, w = list(map(int, input().split()))

maze = [list(eval(input())) for _ in range(h)]

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



max_step = 0

for i in range(h):

    for j in range(w):

        largest_step = 0

#        print("start: ", i, j)

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

            continue

        visited = [[False] * w for _ in range(h)]

        distance = [[-1] * w for _ in range(h)]

        plan = deque()

        step = 0

        plan.appendleft((i, j, step))

        distance[i][j] = step

        visited[i][j] = True

        while plan:

            y, x, step = plan.pop()

#            print(" ", x, y, step)

            # if step > largest_step:

            #     largest_step = step

            for next_direction in direction:

                next_y = y + next_direction[0]

                next_x = x + next_direction[1]

                if -1 == next_x or next_x == w or -1 == next_y or next_y == h or maze[next_y][next_x] == "#" or visited[next_y][next_x]:

                    continue

                distance[next_y][next_x] = distance[y][x] + 1

                visited[next_y][next_x] = True

                plan.appendleft((next_y, next_x, step + 1))

#        print(largest_step)

        # if largest_step > max_step:

        #     max_step = largest_step

        max_step = max(max_step, np.max(np.array(distance)))



print(max_step)

from collections import deque



h, w = list(map(int, input().split()))

maze = [list(eval(input())) for _ in range(h)]

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



max_step = 0

for i in range(h):

    for j in range(w):

        largest_step = 0

#        print("start: ", i, j)

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

            continue

        visited = [[False] * w for _ in range(h)]

        plan = deque()

        step = 1

        plan.appendleft((i, j, step))

        visited[i][j] = True

        while plan:

            y, x, step = plan.pop()

            for next_direction in direction:

                next_y = y + next_direction[0]

                next_x = x + next_direction[1]

                if -1 == next_x or next_x == w or -1 == next_y or next_y == h or maze[next_y][next_x] == "#" or visited[next_y][next_x]:

                    continue

                visited[next_y][next_x] = True

                if step > largest_step:

                    largest_step = step

                plan.appendleft((next_y, next_x, step + 1))

        if largest_step > max_step:

            max_step = largest_step



print(max_step)

import sys
import numpy as np
from collections import deque

h, w = list(map(int, input().split()))
maze = [list(eval(input())) for _ in range(h)]
direction = [(1, 0), (0, 1), (-1, 0), (0, -1)]
max_step = 0
for i in range(h):
    for j in range(w):
        largest_step = 0
        #        print("start: ", i, j)
        if maze[i][j] == "#":
            continue
        visited = [[False] * w for _ in range(h)]
        distance = [[-1] * w for _ in range(h)]
        plan = deque()
        step = 0
        plan.appendleft((i, j, step))
        distance[i][j] = step
        visited[i][j] = True
        while plan:
            y, x, step = plan.pop()
            #            print(" ", x, y, step)
            # if step > largest_step:
            #     largest_step = step
            for next_direction in direction:
                next_y = y + next_direction[0]
                next_x = x + next_direction[1]
                if (
                    -1 == next_x
                    or next_x == w
                    or -1 == next_y
                    or next_y == h
                    or maze[next_y][next_x] == "#"
                    or visited[next_y][next_x]
                ):
                    continue
                distance[next_y][next_x] = distance[y][x] + 1
                visited[next_y][next_x] = True
                plan.appendleft((next_y, next_x, step + 1))
        #        print(largest_step)
        # if largest_step > max_step:
        #     max_step = largest_step
        max_step = max(max_step, np.max(np.array(distance)))
print(max_step)

from collections import deque

h, w = list(map(int, input().split()))
maze = [list(eval(input())) for _ in range(h)]
direction = [(1, 0), (0, 1), (-1, 0), (0, -1)]
max_step = 0
for i in range(h):
    for j in range(w):
        largest_step = 0
        #        print("start: ", i, j)
        if maze[i][j] == "#":
            continue
        visited = [[False] * w for _ in range(h)]
        plan = deque()
        step = 1
        plan.appendleft((i, j, step))
        visited[i][j] = True
        while plan:
            y, x, step = plan.pop()
            for next_direction in direction:
                next_y = y + next_direction[0]
                next_x = x + next_direction[1]
                if (
                    -1 == next_x
                    or next_x == w
                    or -1 == next_y
                    or next_y == h
                    or maze[next_y][next_x] == "#"
                    or visited[next_y][next_x]
                ):
                    continue
                visited[next_y][next_x] = True
                if step > largest_step:
                    largest_step = step
                plan.appendleft((next_y, next_x, step + 1))
        if largest_step > max_step:
            max_step = largest_step
print(max_step)

-import sys -import numpy as np -        distance = [[-1] * w for _ in range(h)] -        step = 0 +        step = 1 -        distance[i][j] = step -            #            print(" ", x, y, step) -            # if step > largest_step: -            #     largest_step = step -                distance[next_y][next_x] = distance[y][x] + 1 +                if step > largest_step: +                    largest_step = step -        #        print(largest_step) -        # if largest_step > max_step: -        #     max_step = largest_step -        max_step = max(max_step, np.max(np.array(distance))) +        if largest_step > max_step: +            max_step = largest_step