from collections import 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

que=deque()
que.append([x,y])
while que:
    v=que.popleft()
    x = v[0]
    y = v[1]
    visited[y][x]=1
    for i in dxdy:
        dx = i[0]
        dy = i[1]
        if((x+dx<w and y+dy<h) and ((x+dx)>-1)and(y+dy)>-1) and not visited[y+dy][x+dx]:
            dist[y+dy][x+dx]=dist[y][x]+1
            que.append([x+dx, y+dy])
max_dist = [0, []]
def max1(a,b):
    if a[0]>b[0]:
        return a
    else:
        return b
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)]

que2 = deque()
que2.append([max_dist[2], max_dist[1]])
while que2:
    v=que2.popleft()
    x = v[0]
    y = v[1]
    visited[y][x]=1
    for i in dxdy:
        dx = i[0]
        dy = i[1]
        if((x+dx<w and y+dy<h) and ((x+dx)>-1)and(y+dy)>-1) and not visited[y+dy][x+dx] and grid[y+dy][x+dx]==".":
            dist[y+dy][x+dx]=dist[y][x]+1
            que2.append([x+dx, y+dy])
for i in range(h):
    for j in range(w):
        max_dist = max1(max_dist, [dist[i][j], i,j])
print(max_dist[0])
