H,W = map(int,input().split())
maze = []
for i in range(H):
    s = input()
    m = []
    for j in range(W):
        m.append(s[j])
    maze.append(m)
d = [[10**9 for i in range(W*H)] for i in range(W*H)]
dx = [0,0,1,-1]
dy = [1,-1,0,0]
for i in range(W*H):
    h = i//W
    w = i%W
    if maze[h][w] == '#':
        continue
    for j in range(4):
        x = w + dx[j]
        y = h + dy[j]
        k = x + y*W
        if 0<=x<=W-1:
            if 0<=y<=H-1:
                if maze[y][x] == '.':
                    d[i][k] = 1
                    d[k][i] = 1
for i in range(W*H):
    d[i][i] = 0
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(W*H):
        for i in range(W*H):
            for j in range(W*H):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
warshall_floyd(d)
ans = 0
for i in range(W*H):
    for j in range(W*H):
        if d[i][j] < 10**9:
            ans = max(ans,d[i][j])
print(ans)