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

def getmax(H2, W2, S):
    T=copy.deepcopy(S)
    lp=True
    st=np.max(T)
    while lp:
        lp=False
        for i in range(1,H2-1):
            for j in range(1,W2-1):
                if (T[i][j]==0 and \
                    ( T[i-1][j]==st or \
                      T[i][j-1]==st or \
                      T[i+1][j]==st or \
                      T[i][j+1]==st)):
                    T[i][j]=st+1
                    lp=True
        st+=1
    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()
