# adj = {
#     1: [2, 3, 4, 8, 9],
#     2: [1, 3, 5],
#     3: [1, 2, 6],
#     4: [1, 6],
#     5: [2, 6, 7],
#     6: [5, 3, 4],
#     7: [5],
#     8: [1],
#     9: [1]
# }

from collections import deque

H, W = map(int, input().split())
d = []
for i in range(H):
    d.append(input())

adj = {(i, j): [] for i in range(H) for j in range(W)}
for i in range(H):
    for j in range(W):
        for m in [(i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)]:
            if 0 <= m[0] <= H - 1 and 0 <= m[1] <= W - 1 and d[i][j] != '#':
                adj[i, j].append(m)


def bfs(g, s):
    if d[s[0]][s[1]] == "#":
        return 0
    visited = {}
    distance = {}
    q = deque()
    q.append(s)
    visited[s] = True
    distance[s] = 0
    while q:
        u = q.popleft()
        for i in g[u]:
            if i not in visited:
                q.append(i)
                visited[i] = True
                distance[i] = distance[u] + 1

    return max(distance.values())


ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, bfs(adj, (i, j)))

print(ans)
