#!/usr/bin/env python3
import sys
import queue

INF = 10 ** 10

def solve(H: int, W: int, S: list):

    # right, bottom, left, top
    h_move = [0, 1, 0, -1]
    w_move = [1, 0, -1, 0]

    max_distance = 0
    for h_start in range(H):
        for w_start in range(W):
            distance = []
            for _ in range(H):
                l = [INF] * W
                distance.append(l)
            q = queue.Queue()
            q.put((h_start, w_start)) # スタート地点
            distance[h_start][w_start] = 0

            while not q.empty():
                h, w = q.get()
                for i in range(4):
                    h_next = h + h_move[i]
                    w_next = w + w_move[i]
                    # マップ外・壁・訪問済みを除外
                    if (h_next < 0 or h_next >= H or w_next < 0 or w_next >= W or S[h_next][w_next] != "." or distance[h_next][w_next] != INF):
                        continue
                    q.put((h_next, w_next))
                    distance[h_next][w_next] = min(distance[h][w] + 1, distance[h_next][w_next])
                    max_distance = max(max_distance, distance[h_next][w_next])

    print(max_distance)
    return

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))
    W = int(next(tokens))
    S = [next(tokens) for _ in range(H)]
    solve(H, W, S)
if __name__ == '__main__':
    main()
