import queue

H,W = map(int,input().split())
S = [list(map(str,input())) for _ in range(H)]

ddx = [1,-1,0,0]
ddy = [0,0,1,-1]

INF = 1<<30
ans = 0
for sx in range(W):
    for sy in range(H):            
        d = 0
        q = queue.Queue()
        dist = [[INF]*W for _ in range(H)]
        dist[sy][sx] = 0
        q.put([sx,sy])
        while not q.empty():
            x,y = q.get()
            for i in range(4):
                dx = ddx[i]
                dy = ddy[i]
                if y+dy<0 or y+dy>=H or x+dx<0 or x+dx>=W:
                    continue
                if S[y+dy][x+dx] == '.' and dist[y+dy][x+dx] == INF:
                    dist[y+dy][x+dx] = dist[y][x] + 1
                    q.put([x+dx,y+dy])
        
        for i in range(H):
            for j in range(W):
                if dist[i][j] != INF:
                    d = max(d,dist[i][j])
            
        ans = max(ans,d)
        
print(ans)