from collections import deque
INF = 1e9
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]


def bfs(sy, sx):
    que = deque()
    que.append((sy, sx))
    d[sy][sx] = 0
    m = 0
    xy = [[0]*c for _ in range(r)]
    while len(que) > 0:
        y, x = que.popleft()
        if xy[y][x] !=0:
            break
        xy[y][x]=1

        for i in range(4):
            ny = y+dy[i]
            nx = x+dx[i]
            if 0 <= ny and ny < r and 0 <= nx and nx < c and wall[ny][nx] != "#" and d[ny][nx] == INF:
                que.append((ny, nx))
                d[ny][nx] = d[y][x]+1
                m = max(d[ny][nx],m)

    return m


r, c = map(int, input().split())
wall = [list(input()) for _ in range(r)]

ans = 0
for i in range(r):
    for j in range(c):
        d = [[INF]*c for _ in range(r)]
        a = bfs(i, j)
        ans = max(ans, a)
print(ans)
