import sys

from collections import deque



read = sys.stdin.read

readline = sys.stdin.readline



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

S = tuple(map(tuple, read().split()))





def bfs(grid, start):

    distance = [[-1] * W for _ in range(H)]

    queue = deque([start])

    distance[start[0]][start[1]] = 0

    while queue:

        x, y = queue.popleft()



        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):

            new_y, new_x = y + j, x + i

            if 0 <= new_y < W and 0 <= new_x < H:

                if grid[new_x][new_y] == '.' and distance[new_x][new_y] == -1:

                    distance[new_x][new_y] = distance[x][y] + 1

                    queue.append((new_x, new_y))

        if not queue:

            return distance[x][y]





answer = 0

for i in range(H):

    for j in range(W):

        if S[i][j] == '#':

            continue



        tmp = bfs(S, (i, j))

        if tmp > answer:

            answer = tmp



print(answer)

import sys

from collections import deque



read = sys.stdin.readline



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

S = [list('#' * (W + 2))] + [['#'] + list(read().rstrip()) + ['#'] for _ in range(H)] + [list('#' * (W + 2))]





def bfs(grid, start):

    distance = [[-1] * (W + 2) for _ in range(H + 2)]

    queue = deque([start])

    distance[start[0]][start[1]] = 0

    while queue:

        x, y = queue.popleft()



        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):

            new_y, new_x = y + j, x + i

            if grid[new_x][new_y] == '.' and distance[new_x][new_y] == -1:

                distance[new_x][new_y] = distance[x][y] + 1

                queue.append((new_x, new_y))

        if not queue:

            return distance[x][y]





answer = 0

for i in range(1, H + 1):

    for j in range(1, W + 1):

        if S[i][j] == '#':

            continue



        cnt = 0

        for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):

            new_y, new_x = dy + j, dx + i

            if S[new_x][new_y] == '.':

                cnt += 1



        if cnt > 2:

            continue



        tmp = bfs(S, (i, j))

        if tmp > answer:

            answer = tmp



print(answer)

import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
H, W = list(map(int, readline().split()))
S = tuple(map(tuple, read().split()))


def bfs(grid, start):
    distance = [[-1] * W for _ in range(H)]
    queue = deque([start])
    distance[start[0]][start[1]] = 0
    while queue:
        x, y = queue.popleft()
        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            new_y, new_x = y + j, x + i
            if 0 <= new_y < W and 0 <= new_x < H:
                if grid[new_x][new_y] == "." and distance[new_x][new_y] == -1:
                    distance[new_x][new_y] = distance[x][y] + 1
                    queue.append((new_x, new_y))
        if not queue:
            return distance[x][y]


answer = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        tmp = bfs(S, (i, j))
        if tmp > answer:
            answer = tmp
print(answer)

import sys
from collections import deque

read = sys.stdin.readline
H, W = list(map(int, input().split()))
S = (
    [list("#" * (W + 2))]
    + [["#"] + list(read().rstrip()) + ["#"] for _ in range(H)]
    + [list("#" * (W + 2))]
)


def bfs(grid, start):
    distance = [[-1] * (W + 2) for _ in range(H + 2)]
    queue = deque([start])
    distance[start[0]][start[1]] = 0
    while queue:
        x, y = queue.popleft()
        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            new_y, new_x = y + j, x + i
            if grid[new_x][new_y] == "." and distance[new_x][new_y] == -1:
                distance[new_x][new_y] = distance[x][y] + 1
                queue.append((new_x, new_y))
        if not queue:
            return distance[x][y]


answer = 0
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] == "#":
            continue
        cnt = 0
        for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            new_y, new_x = dy + j, dx + i
            if S[new_x][new_y] == ".":
                cnt += 1
        if cnt > 2:
            continue
        tmp = bfs(S, (i, j))
        if tmp > answer:
            answer = tmp
print(answer)

-read = sys.stdin.read -readline = sys.stdin.readline -H, W = list(map(int, readline().split())) -S = tuple(map(tuple, read().split())) +read = sys.stdin.readline +H, W = list(map(int, input().split())) +S = ( +    [list("#" * (W + 2))] +    + [["#"] + list(read().rstrip()) + ["#"] for _ in range(H)] +    + [list("#" * (W + 2))] +) -    distance = [[-1] * W for _ in range(H)] +    distance = [[-1] * (W + 2) for _ in range(H + 2)] -            if 0 <= new_y < W and 0 <= new_x < H: -                if grid[new_x][new_y] == "." and distance[new_x][new_y] == -1: -                    distance[new_x][new_y] = distance[x][y] + 1 -                    queue.append((new_x, new_y)) +            if grid[new_x][new_y] == "." and distance[new_x][new_y] == -1: +                distance[new_x][new_y] = distance[x][y] + 1 +                queue.append((new_x, new_y)) -for i in range(H): -    for j in range(W): +for i in range(1, H + 1): +    for j in range(1, W + 1): +            continue +        cnt = 0 +        for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)): +            new_y, new_x = dy + j, dx + i +            if S[new_x][new_y] == ".": +                cnt += 1 +        if cnt > 2: