from collections import deque

H, W = map(int, input().split())
field = ['#' * (W+2)] * (H+2)
for i in range(1, H+1):
    field[i] = '#' + input() + '#'
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
ans = 0

for i in range(1, H+1):
    for j in range(1, W+1):
        q = deque()
        q.append([i, j])
        dist = [[-1 for _ in range(W+2)] for _ in range(H+2)]
        dist[i][j] = 0
        dist_max = 0
        while len(q) != 0:
            current = q.popleft()
            x = current[0]
            y = current[1]

            for d in range(4):
                next_x = x + dx[d]
                next_y = y + dy[d]

                if field[next_x][next_y] == '#':
                    continue

                if dist[next_x][next_y] != -1:
                    continue

                q.append([next_x, next_y])
                dist[next_x][next_y] = dist[x][y] + 1
                dist_max = max(dist_max, dist[next_x][next_y])
        ans = max(ans, dist_max)
print(ans)
