import queue



def shortestpath(y0, x0):

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

    step_cnt[y0][x0] = 0

    q.put((y0, x0))

    while not q.empty():

        y, x = q.get()

        for i in range(4):

            y_next = y + dy[i]

            x_next = x + dx[i]

            if 0 <= y_next < h and 0 <= x_next < w\

            and maze[y_next][x_next] == '.'\

            and step_cnt[y_next][x_next] == -1:

                q.put((y_next, x_next))

                step_cnt[y_next][x_next] = step_cnt[y][x] + 1

                    

    return step_cnt[y][x]



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

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

dy = [-1, 0, 1, 0]

dx = [0, -1, 0, 1]

q = queue.Queue()



max_steps = -1

for y0 in range(h):

    for x0 in range(w):

        if maze[y0][x0] != '#':

            max_steps = max(max_steps, shortestpath(y0, x0))



print(max_steps)

from collections import deque



def shortestpath(y0, x0):

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

    step_cnt[y0][x0] = 0

    q.append((y0, x0))

    while q:

        y, x = q.popleft()

        for i in range(4):

            y_next = y + dy[i]

            x_next = x + dx[i]

            if 0 <= y_next < h and 0 <= x_next < w\

            and maze[y_next][x_next] == '.'\

            and step_cnt[y_next][x_next] == -1:

                q.append((y_next, x_next))

                step_cnt[y_next][x_next] = step_cnt[y][x] + 1

                    

    return step_cnt[y][x]



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

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

dy = [-1, 0, 1, 0]

dx = [0, -1, 0, 1]

q = deque()



max_steps = -1

for y0 in range(h):

    for x0 in range(w):

        if maze[y0][x0] != '#':

            max_steps = max(max_steps, shortestpath(y0, x0))



print(max_steps)

import queue


def shortestpath(y0, x0):
    step_cnt = [[-1] * w for _ in range(h)]
    step_cnt[y0][x0] = 0
    q.put((y0, x0))
    while not q.empty():
        y, x = q.get()
        for i in range(4):
            y_next = y + dy[i]
            x_next = x + dx[i]
            if (
                0 <= y_next < h
                and 0 <= x_next < w
                and maze[y_next][x_next] == "."
                and step_cnt[y_next][x_next] == -1
            ):
                q.put((y_next, x_next))
                step_cnt[y_next][x_next] = step_cnt[y][x] + 1
    return step_cnt[y][x]


h, w = map(int, input().split())
maze = [[x for x in input()] for _ in range(h)]
dy = [-1, 0, 1, 0]
dx = [0, -1, 0, 1]
q = queue.Queue()
max_steps = -1
for y0 in range(h):
    for x0 in range(w):
        if maze[y0][x0] != "#":
            max_steps = max(max_steps, shortestpath(y0, x0))
print(max_steps)

from collections import deque


def shortestpath(y0, x0):
    step_cnt = [[-1] * w for _ in range(h)]
    step_cnt[y0][x0] = 0
    q.append((y0, x0))
    while q:
        y, x = q.popleft()
        for i in range(4):
            y_next = y + dy[i]
            x_next = x + dx[i]
            if (
                0 <= y_next < h
                and 0 <= x_next < w
                and maze[y_next][x_next] == "."
                and step_cnt[y_next][x_next] == -1
            ):
                q.append((y_next, x_next))
                step_cnt[y_next][x_next] = step_cnt[y][x] + 1
    return step_cnt[y][x]


h, w = map(int, input().split())
maze = [[x for x in input()] for _ in range(h)]
dy = [-1, 0, 1, 0]
dx = [0, -1, 0, 1]
q = deque()
max_steps = -1
for y0 in range(h):
    for x0 in range(w):
        if maze[y0][x0] != "#":
            max_steps = max(max_steps, shortestpath(y0, x0))
print(max_steps)

-import queue +from collections import deque -    q.put((y0, x0)) -    while not q.empty(): -        y, x = q.get() +    q.append((y0, x0)) +    while q: +        y, x = q.popleft() -                q.put((y_next, x_next)) +                q.append((y_next, x_next)) -q = queue.Queue() +q = deque()