#!/usr/bin/env python3
import sys
from collections import deque

INF = float("inf")

XX = [1, -1, 0, 0]
YY = [0, 0, 1, -1]


def main():

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

    dist = [[-1]*W for _ in range(H)]

    ans = 0
    for h in range(H):
        for w in range(W):
            # スタート位置 (h, w)
            if S[h][w] == "#":
                continue
            # 距離
            dist = [[INF]*W for _ in range(H)]

            q = deque([(h, w, 0)])
            while len(q) > 0:
                y, x, p = q.popleft()
                # 上下左右に移動可能ならば、移動して更新する
                for dx, dy in zip(XX, YY):
                    if y + dy < 0 or y + dy >= H:
                        continue
                    if x + dx < 0 or x + dx >= W:
                        continue
                    if S[y+dy][x+dx] == "#":
                        continue
                    if p + 1 < dist[y+dy][x+dx]:
                        dist[y+dy][x+dx] = p+1
                        q.append((y+dy, x+dx, p+1))

            # 一番遠く
            toku = -1
            for i in range(H):
                for j in range(W):
                    if dist[i][j] != INF:
                        toku = max(dist[i][j], toku)
            ans = max(toku, ans)

    print(ans)


if __name__ == '__main__':
    main()
