#!/usr/bin/env python3
import copy
import numpy as np

def getmax(H2, W2, S):
    T=copy.deepcopy(S)
    Tn=copy.deepcopy(S)
    lp=True
    st=0
    while lp:
        lp=False
        for i in range(1,H2-1):
            for j in range(1,W2-1):
                if T[i][j]==0:
                    if (T[i-1][j]<1 and
                        T[i][j-1]<1 and
                        T[i+1][j]<1 and
                        T[i][j+1]<1):
                        continue
                    Tn[i][j]=max(T[i-1][j],T[i][j-1],T[i+1][j],T[i][j+1])+1
                    lp=True
        T=copy.deepcopy(Tn)
    return(np.max(T))

def solve(H2, W2, S):
    #try1
    lp=True

    ans=0
    for i in range(1,H2-1):
        for j in range(1,W2-1):
            if S[i][j]==-1:
                continue
            if S[i][j]==0:
                S[i][j]=1
                ans=max(ans, getmax(H2, W2, S))
                S[i][j]=0

    print(ans-1)
    return

def main():
    H, W = map(int, input().split())
    SS=[[-1 for _ in range(W+2)] for _ in range(H+2)]
    S=[]
    for _ in range(H):
        S.append(list(input()))
    for i in range(H):
        for j in range(W):
            SS[i+1][j+1]=0 if S[i][j]=="." else -1
    solve(H+2, W+2, SS)

if __name__ == '__main__':
    main()
