import numpy as np
# import math
# import copy
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
# from collections import deque


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

    INF = 1001001001
    res = 0

    di = [-1,0,1,0]
    dj = [0,-1,0,1]

    path = np.full((H,W,H,W),INF)

    for si in range(H):
        for sj in range(W):
            for k in range(4):
                gi = si + di[k]
                gj = sj + dj[k]
                if (gi<0)|(gi>=H)|(gj<0)|(gj>=W):
                    continue
                if S[gi][gj] == '#':
                    continue
                if (si==gi)&(sj==gj):
                    path[si,sj,gi,gj] = 0
                else:
                    path[si,sj,gi,gj] = 1

    for mi in range(H):
        for mj in range(W):
            for si in range(H):
                for sj in range(W):
                    for gi in range(H):
                        for gj in range(W):
                            temp = min(path[si,sj,gi,gj],path[si,sj,mi,mj]+path[mi,mj,gi,gj])
                            path[si,sj,gi,gj] = temp

    res = np.max(path[path<INF])


    print(res)


main()
