import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
 
from functools import reduce
# from math import *
from fractions import *
H, W = map(int, readline().split())
S = [0 for i in range(H)]
for i in range(H):
    S[i] = readline().decode().strip()

def bfs(start, goal, H, W):
    visited = [False for _ in range(H * W)]
    import queue
    q = queue.Queue()
    q.put((start[0], start[1], 0))
    while not q.empty():
        (i, j, dist) = q.get()
        if (i, j) == goal:
            return dist
        for dy in range(-1, 2):
            for dx in range(-1, 2):
                if dx * dy != 0 or dx == dy:
                    continue
                if i + dy < 0 or i + dy >= H or j + dx < 0 or j + dx >= W:
                    continue
                if S[i + dy][j + dx] == '#':
                    continue
                if visited[(i + dy) * W + j + dx]:
                    continue
                q.put((i + dy, j + dx, dist + 1))
    return -1

ans = 0
for i in range(H * W):
    start = (i // W, i % W)
    if S[start[0]][start[1]] == '#':
        continue
    for j in range(H * W):
        goal = (j // W, j % W)
        if S[goal[0]][goal[1]] == '#':
            continue
        if start == goal:
            continue
        ans = max(ans, bfs(start, goal, H, W))
print(ans)
