H, W = map(int, input().split())

S = [["#"]*W for i in range(H)]
      
for i in range(H):
    S[i] = list(input())

Sp = [["#"]*(W+2) for i in range(H+2)]
       
for i in range(1,H+1):
    for j in range(1,W+1):
        Sp[i][j] = S[i-1][j-1]

mx = 0

for i in range(1,H+1):
    for j in range(1,W+1):
        if Sp[i][j] == ".":
            Wo = [[-1]*(W+2) for i in range(H+2)]
            Wo[i][j] = 0
            cnt = 1
            while cnt>0:
                cnt = 0
                for k in range(1,H+1):
                    for l in range(1,W+1):
                        if Wo[k][l] != -1:
                            if Sp[k-1][l] == ".":
                                if Wo[k-1][l] == -1:
                                    Wo[k-1][l] = Wo[k][l]+1
                                    cnt+=1
                            if Sp[k+1][l] == ".":
                                if Wo[k+1][l] == -1:
                                    Wo[k+1][l] = Wo[k][l]+1
                                    cnt+=1
                            if Sp[k][l-1] == ".":
                                if Wo[k][l-1] == -1:
                                    Wo[k][l-1] = Wo[k][l]+1
                                    cnt+=1
                            if Sp[k][l+1] == ".":
                                if Wo[k][l+1] == -1:
                                    Wo[k][l+1] = Wo[k][l]+1
                                    cnt+=1
            for k in range(1,H+1):
                mx=max(mx,max(Wo[k]))

print(mx)            