h,w=map(int,input().split())
data=[]
data.append(list("#"*(w+2)))
for i in range(h):
    s=input()
    s="#"+s+"#"
    lists=list(s)
    data.append(lists)
data.append("#"*(w+2))
s=0
graph={i:[] for i in range(1,h*w+1)}
for i in range(1,h+1):
    for j in range(1,w+1):
        if data[i][j]==".":
            a=w*(i-1)+j
            s=a
            if data[i+1][j]==".":
                b=w*(i)+j
                graph[b].append(a)
                graph[a].append(b)

            if data[i][j+1]==".":
                b=w*(i-1)+j+1
                graph[b].append(a)
                graph[a].append(b)

from collections import deque

def how_far_from(s,n):
    d=deque()
#頂点sからどのくらいの距離にあるのかを返す関数
    parent=[0 for i in range(n+1)]
    visited=[False for i in range(n+1)]
    visited[s]=True
    d.append((s,0))

    how_far={i:[] for i in range(n+1)}
    while d:
        node=d.popleft()
        for point in graph[node[0]]:
            if visited[point]==False:
      
                visited[point]=True

                d.append((point,node[1]+1))
                how_far[node[1]+1].append(point)

    return how_far

P=how_far_from(s,h*w)


for i in range(h*w,-1,-1):
    if P[i]:
        start=P[i][0]
        break
Q=how_far_from(start,h*w)
for i in range(h*w,-1,-1):
    if Q[i]:
        print(i)
        break