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, h, w):

    visited = np.full(S.shape, 10**9)
    visited[h][w] = 1

    que = deque()
    que.append((h, w))

    while len(que) != 0:
        pos = que.popleft()
        acc = visited[pos[0]][pos[1]]

        for adj in adjacent_4(pos[0], pos[1]):
            if S[adj[0]][adj[1]] == '#':
                continue
            acc_ = acc + 1
            if acc_ >= visited[adj[0]][adj[1]]:
                continue
            visited[adj[0]][adj[1]] = acc_
            que.append(adj)

    visited[visited == 10**9] = 0
    return visited.max() - 1


"""
ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        ans = max(ans, bfs(S, h, w))
"""
ans = max(bfs(S, h, w) for h in range(H) for w in range(W) if S[h][w] != '#')
print(int(ans))