from collections import deque

h,w = map(int, input().split( ))

s = ["#"*(w+2)]
for i in range(h):
    si = "#"+input()+"#"
    s.append(si)
s.append("#"*(w+2))
nb = [(-1,0),(1,0),(0,1),(0,-1)]
inf = 10000
def bfs(x_,y_):
    dist = [[inf for i in range(w+2)] for j in range(h+2)]
    Q = deque()
    dist[x_][y_] = 0
    Q.append((x_,y_))
    while Q:
        x,y = Q.popleft()
        for u,v in nb:
            if s[x+u][y+v]!="#":
                if dist[x+u][y+v]>dist[x][y]+1:
                    dist[x+u][y+v]=dist[x][y]+1
                    Q.append((x+u,y+v))
    res = -1
    for i in range(h+2):
        for j in range(w+2):
            if dist[i][j]<inf:
                res = max(res,dist[i][j])
    return res
ans = 0
for i in range(1,h+1):
    for j in range(1,w+1):
       
        ans = max(ans,bfs(i,j))
print(ans)
    
    