import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    res = 0
    for sh in range(H):
        for sw in range(W):
            if S[sh][sw] != "#":
                for gh in range(H):
                    for gw in range(W):
                        if S[gh][gw] != "#":
                            maze = [[f_inf] * W for _ in range(H)]
                            maze[sh][sw] = 0
                            que = deque([[sh, sw]])
                            while que:
                                h, w = que.popleft()
                                for dh, dw in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
                                    next_h, next_w = h + dh, w + dw
                                    if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                                        continue
                                    elif S[next_h][next_w] == "#":
                                        continue
                                    else:
                                        if maze[next_h][next_w] > maze[h][w] + 1:
                                            maze[next_h][next_w] = maze[h][w] + 1
                                            que.append([next_h, next_w])
                            if maze[gh][gw] != f_inf:
                                res = max(res, maze[gh][gw])
    print(res)


if __name__ == '__main__':
    resolve()
