#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))

(require 'sb-queue)

(defun get-shortest (h w map start-x start-y)
  (let ((q (sb-queue:make-queue :initial-contents (list (list start-x start-y 0)))))
    (prog1
        (loop until (sb-queue:queue-empty-p q)
              for (x y score) = (sb-queue:dequeue q)
              for next-score = (1+ score)
              maximize (prog1
                           (setf (aref map y x) score)
                         ;; left
                         (when (and (<= 0 (1- x))
                                    (zerop (aref map y (1- x)))
                                    (or (/= y start-y)
                                        (/= (1- x) start-x)))
                           (sb-queue:enqueue (list (1- x) y next-score) q))
                         ;; up
                         (when (and (<= 0 (1- y))
                                    (zerop (aref map (1- y) x))
                                    (or (/= (1- y) start-y)
                                        (/= x start-x)))
                           (sb-queue:enqueue (list x (1- y) next-score) q))
                         ;; right
                         (when (and (< (1+ x) w)
                                    (zerop (aref map y (1+ x)))
                                    (or (/= y start-y)
                                        (/= (1+ x) start-x)))
                           (sb-queue:enqueue (list (1+ x) y next-score) q))
                         ;; down
                         (when (and (< (1+ y) h)
                                    (zerop (aref map (1+ y) x))
                                    (or (/= (1+ y) start-y)
                                        (/= x start-x)))
                           (sb-queue:enqueue (list x (1+ y) next-score) q))))
      (reset-map h w map))))

(defun solve (h w map)
  (loop for y from 0 below h
        maximize (loop for x from 0 below w
                       if (/= -1 (aref map y x))
                       maximize (get-shortest h w map x y))))

(defun reset-map (h w map)
  (loop for y from 0 below h
        do (loop for x from 0 below w
                 if (/= -1 (aref map y x))
                 do (setf (aref map y x) 0))))

#-swank
(let* ((h (read))
       (w (read))
       (map (make-array (list h w) :element-type 'fixnum)))
  (loop for y from 0 below h
        do (loop for x from 0 below w
                 for char = (read-char)
                 do (setf (aref map y x)
                          (if (char= char #\.)
                              0
                              -1)))
        do (read-char))
  (format t "~A~%" (solve h w map)))
