import numpy as np
import queue

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

maze = np.zeros((H, W))


for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == '.':
            maze[i, j] = 1

max_run = 0


tan = [[1, 0], [-1, 0], [0, 1], [0, -1]]

def max_route(h, w):
    g = (21, 21)
    q = queue.Queue()
    checker = maze.copy()
    q.put((h, w))
    q.put(g)

    run = 0

    while not q.empty():
        target = q.get()
        if target == g:
            if not q.empty():
                run += 1
                q.put(g)
        else:
            for t in tan:
                check = [target[0]+t[0], target[1]+t[1]]
                if 0 <= check[0] < H and 0 <= check[1] < W:
                    if checker[check[0], check[1]] == 1:
                        q.put((check[0], check[1]))
                        checker[check[0], check[1]] = 2

    return run


for h in range(H):
    for w in range(W):
        if maze[h, w] == 0:
            continue
        cur = max_route(h, w)
        if cur > max_run:
            max_run = cur

print(max_run)
