from collections import deque
que=deque()
h,w = map(int, input().split())

grid = []

for i in range(h):
    s = list(input().rstrip())
    grid.append(s)
dxdy = [[0, 1], [1,0], [-1, 0], [0, -1]]
visited = [[0]*w for _ in range(h)]
dist = [[0]*w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if grid[i][j]==".":
            y = i
            x = j
            break



dist[y][x] = 0
max_dist = [0, []]
def max1(a,b):
    if a[0]>b[0]:
        return a
    else:
        return b
def dfs(x, y):
    visited[y][x]=1
    for dydx in dxdy:
        if (x+dydx[0]<w and y+dydx[1]<h) and (x+dydx[0]>-1 and y+dydx[1]>-1) and not visited[y+dydx[1]][x+dydx[0]]:
            if grid[y+dydx[1]][x+dydx[0]]==".":
                dist[y+dydx[1]][x+dydx[0]] = dist[y][x]+1
                dfs(x+dydx[0], y+dydx[1])
dfs(x, y)

for i in range(h):
    for j in range(w):
        max_dist = max1(max_dist, [dist[i][j], i,j])

visited = [[0]*w for _ in range(h)]
dist = [[0]*w for _ in range(h)]
dfs(max_dist[2],max_dist[1])


for i in range(h):
    for j in range(w):
        max_dist = max1(max_dist, [dist[i][j], i,j])
print(max_dist[0])
