from collections import deque


def read():
    H, W = list(map(int, input().split()))
    S = list()
    S.append(['#'] * (W+2))
    for h in range(H):
        s = list('#' + input() + '#')
        S.append(s)
    S.append(['#'] * (W+2))
    return H, W, S


def bfs(y, x, H, W, S):
    visited = [[False for j in range(W+2)] for i in range(H+2)]
    q = deque()
    q.appendleft((y, x, 0))
    max_depth = 0
    while len(q) > 0:
        y, x, depth = q.pop()
        visited[y][x] = True
        max_depth = max(max_depth, depth)
        for dy, dx in [(0,1), (1,0), (0,-1), (-1,0)]:
            ny, nx = y+dy, x+dx
            if S[ny][nx] == '.' and not visited[ny][nx]:
                q.appendleft((ny, nx, depth+1))
    return max_depth


def reset_depth(H, W, depth, S, INF=10**7):
    for i in range(H+2):
        for j in range(W+2):
            if S[i][j] == '#':
                depth[i][j] = -2
            else:
                depth[i][j] = -1


def solve(H, W, S):
    dist_max = 0
    for i in range(1, H+1):
        for j in range(1, W+1):
            if S[i][j] == '.':
                d = bfs(i, j, H, W, S)
                dist_max = max(d, dist_max)
    return dist_max


if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))
