(defun main (&rest argv)
  (declare (ignorable argv))
  (let* ((n (read))
         (p (make-array n :element-type 'integer)))
    (dotimes (i n)
      (let* ((q (read)))
        (if (zerop q)
            (progn
             (format t "0~%")
             (return-from main 0))
            (setf (aref p i) q))))
    (let ((r (if (= n 1)
                 (mod (aref p 0) 9)
                 (reduce #'(lambda (x acc) (mod (* x acc) 9)) p))))
      (format t "~d~%" (if (zerop r)
                           9
                           r)))))

(main)