import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
# 距離をキューから取り出してから更新する
H, W = map(int, input().split())
# 縦H,横W
c = [None]*H
for i in range(H):
    c[i] = input()
# print(c)


def BFS(x, y):
    dist = [-1]*H
    for k in range(H):
        dist[k] = [-1]*W

    d = deque()
    d.append((x, y, 0))
    while(len(d) != 0):
        h, w, distance = d.popleft()
        if c[h][w] == '.' and dist[h][w] == -1:
            dist[h][w] = distance
            if h != 0 and c[h-1][w] == '.':
                # if dist[h-1][w] == -1:
                d.append((h-1, w, distance+1))
            if h != H-1 and c[h+1][w] == '.':
                # if dist[h+1][w] == -1:
                d.append((h+1, w, distance+1))
            if w != 0 and c[h][w-1] == '.':
                # if dist[h][w-1] == -1:
                d.append((h, w-1, distance+1))
            if w != W-1 and c[h][w+1] == '.':
                # if dist[h][w+1] == -1:
                d.append((h, w+1, distance+1))
    # print(dist)
    return dist


ans = -1
for i in range(H):
    for j in range(W):
        if c[i][j] == '.':
            tmp = max(max(BFS(i, j)))
            ans = max(ans, tmp)
print(ans)
