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

def getmax(H2, W2, S):
    lp=True
    st=0
    while lp:
        lp=False
        for i in range(1,H2-1):
            for j in range(1,W2-1):
                if S[i][j]==0:
                    if (S[i-1][j]<1 and
                        S[i][j-1]<1 and
                        S[i+1][j]<1 and
                        S[i][j+1]<1):
                        continue
                    S[i][j]=max(S[i-1][j],S[i][j-1],S[i+1][j],S[i][j+1])+1
                    lp=True
    maxS=np.max(S)
    n=0
    p=[]
    for i in range(1,H2-1):
        for j in range(1,W2-1):
            if S[i][j]==maxS:
                n+=1
                p.append((i,j))

    return(maxS, n, p)

def solve(H2, W2, S):
    T=copy.deepcopy(S)
    #try1
    lp=True
    while lp:
        for i in range(1,H2-1):
            for j in range(1,W2-1):
                if S[i][j]==0:
                    S[i][j]=1
                    lp=False
                if not lp:
                    break
            if not lp:
                break

    maxS, n, p=getmax(H2, W2, S)

    ans=0
    #print("#",maxS, n, p)
    for k in range(n):
        S=copy.deepcopy(T)
        S[p[k][0]][p[k][1]]=1
        maxS, _, _=getmax(H2, W2, S)
        ans=max(maxS, ans)

    #while True:
    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()
