# -*- coding: utf-8 -*-
# D

# BFSで各点から到達可能な最も遠いところを探索する
# 1回探索はO(HW)なのでO(HHWW)?
# BFSなのでdeque / queue使う

# from collections import deque
import queue

H, W = map(int, input().split())

data = [None] * H
for i in range(H):
    data[i] = input()


def judge(h, w, dist):
    if (h >=0) and (h < H) and (w >= 0) and (w < W):
        if data[h][w] == '.' and dist[h][w] == -1:
            return True
        else:
            return False
    return False


def bfs(h, w):
    dist = [[-1] * W for i in range(H)]
    # q = deque()
    q = queue.Queue()

    max_dist = 0
    dist[h][w] = 0
    # q.append((h, w, 0))
    q.put((h, w, 0))

    # while len(q) > 0:
    while not q.empty():
        # h, w, val = q.popleft()
        h, w, val = q.get()
        dist[h][w] = val
        max_dist = max(max_dist, val)

        if judge(h+1, w, dist):
            q.put((h+1, w, val+1))
        if judge(h-1, w, dist):
            q.put((h-1, w, val+1))
        if judge(h, w+1, dist):
            q.put((h, w+1, val+1))
        if judge(h, w-1, dist):
            q.put((h, w-1, val+1))

    return max_dist


ans = 0
for h in range(H):
    for w in range(W):
        if data[h][w] == '.':
            res = bfs(h, w)
            # print(h, w, res)
            ans = max(ans, res)

print(ans)
