from collections import Counter, defaultdict
import sys

sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
from copy import deepcopy
import queue
from collections import deque


def minload(data_copy, high_i, width_i, high_j, width_j, high, width):
    data = deepcopy(data_copy)
    count = 0
    now_point = set()
    now_point.add((high_i, width_i))
    next_point = set()
    goal = [high_j, width_j]
    move = [[1, 0], [0, 1], [-1, 0], [0, -1]]

    while 1:
        for now_i, now_j in now_point:
            data[now_i][now_j] = count
            for move_i, move_j in move:
                next_i, next_j = now_i + move_i, now_j + move_j
                if next_i < 0 or next_i >= high or next_j < 0 or next_j >= width:
                    continue
                if data[next_i][next_j] != ".":
                    continue
                # data[next_i][next_j] = count
                next_point.add((next_i, next_j))

        if data[goal[0]][goal[1]] != ".":
            break
        now_point = next_point
        next_point = set()
        count += 1

    # print(data)

    return data[goal[0]][goal[1]]



def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    ans = 0

    for high_i in range(high):
        for width_i in range(width):
            for high_j in range(high_i, high):
                for width_j in range(width_i, width):
                    # print(high_i, width_i, high_j, width_j)
                    if high_i == high_j and width_i == width_j:
                        continue
                    if data[high_i][width_i] == data[high_j][width_j] == ".":
                        ans = max(ans, minload(data, high_i, width_i, high_j, width_j, high, width))
                        # print(ans, data)

    print(ans)


if __name__ == '__main__':
    main()
