from collections import deque
from itertools import product


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


def bfs(y, x, H, W, S):
    dirs = [(0, 1), (1, 0), (0, -1), (-1, 0)]
    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 dirs:
            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 solve(H, W, S):
    dist_max = 0
    for i, j in product(range(1, H+1), 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)))
