import sys
import numpy as np
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H, W = map(int, readline().split())
S = np.array([list(readline().decode('utf-8').rstrip()) for _ in range(H)])


def adjacent_4(h, w):
    ret = []
    for (dh, dw) in [(0, 1), (1, 0), (0, -1), (-1, 0)]:
        h_ = h + dh
        w_ = w + dw

        if (0 <= h_) & (h_ < H) & (0 <= w_) & (w_ < W):
            ret.append((h_, w_))
    return ret


def bfs(S, visited, h, w, cnt):

    que = deque()
    for adj in adjacent_4(h, w):
        que.append([adj, cnt])

    while len(que) != 0:
        target, cnt_ = que.popleft()
        if (visited[target[0]][target[1]] !=
                -1) | (S[target[0]][target[1]] == '#'):
            continue
        visited[target[0]][target[1]] = cnt_
        for adj in adjacent_4(target[0], target[1]):
            que.append([adj, cnt_ + 1])


ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue

        visited = np.full(S.shape, -1)
        visited[h][w] = 0
        bfs(S, visited, h, w, 1)
        ans = max(ans, visited.max())

print(ans)