from collections import deque
import numpy as np


def bfs(y, x, H, W, S):
    dirs = [(-1, 0), (0, -1), (1, 0), (0, 1)]
    visited = np.zeros((H+2, W+2), dtype=np.bool)
    q = deque()
    q.append((y, x, 0))
    #visited[y][x] = True
    max_depth = 1
    while q:
        y, x, d = q.popleft()
        max_depth = max(max_depth, d)
        for dy, dx in dirs:
            ny, nx = y + dy, x + dx
            if not visited[ny][nx] and S[ny][nx] == '.':
                visited[ny][nx] = True
                q.append((ny, nx, d+1))
    return max_depth


def solve():
    H, W = map(int, input().split())
    S = list()
    S.append(['#'] * (W+2))
    for _ in range(H):
        buf = input()
        S.append(list('#' + buf + '#'))
    S.append(['#'] * (W+2))

    dist_max = 0
    for y in range(H):
        for x in range(W):
            if S[y+1][x+1] == '.':
                d = bfs(y+1, x+1, H, W, S)
                dist_max = max(d, dist_max)
    print(dist_max)


if __name__ == '__main__':
    solve()
