IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT SYSIN ASSIGN TO KEYBOARD ORGANIZATION LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
    FD SYSIN.
        01 INDATA PIC X(2000000).
WORKING-STORAGE SECTION.
01 INF        PIC 9(19) VALUE 1000000000000000000.
01 INP        PIC X(21000).
01 maxlen     PIC 9(10) VALUE 100 COMP.
01 cur        PIC 9(10) VALUE 1 COMP.
01 i          PIC 9(10) VALUE 1 COMP.
01 j          PIC 9(10) COMP.
01 len        PIC 9(10) COMP.
01 ans        PIC 9(36) VALUE 1.
01 zs         PIC Z(35)9.
01 N          PIC 9(10).
01 flg        PIC 9(1) VALUE ZERO.
01 A1.
   03 A11 OCCURS 100 DEPENDING ON N DESCENDING KEY A INDEXED BY K.
      05 A    PIC 9(19).

PROCEDURE DIVISION.
  ACCEPT N.
  OPEN INPUT SYSIN.
  READ SYSIN INTO INP.
  CLOSE SYSIN.
  MOVE N TO maxlen.
  PERFORM maxlen TIMES
    PERFORM VARYING j FROM cur BY 1 UNTIL INP(j:1) = SPACE
    END-PERFORM
    COMPUTE len = j - cur
    MOVE INP(cur:len) TO A(i)
    IF ZERO = A(i)
      MOVE 1 TO flg
      EXIT PERFORM
    END-IF
    COMPUTE cur = j + 1
    ADD 1 TO i
  END-PERFORM.

  IF 1 = flg
    DISPLAY ZERO
  ELSE
    PERFORM VARYING i FROM 1 BY 1 UNTIL maxlen < i
      IF INF < A(i)
        MOVE 1 TO flg
        EXIT PERFORM
      END-IF
      MULTIPLY ans BY A(i) GIVING ans
      IF INF < ans
        MOVE 1 TO flg
        EXIT PERFORM
      END-IF
    END-PERFORM
    IF 1 = flg
      DISPLAY -1
    ELSE
      MOVE ans TO zs
      DISPLAY FUNCTION TRIM(zs)
    END-IF
  END-IF.
  STOP RUN.
