IDENTIFICATION DIVISION.
PROGRAM-ID. 160C.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 INP        PIC X(1600000).
*>
WORKING-STORAGE SECTION.
01 S          PIC  X(20).
01 K          PIC  9(7).
01 N          PIC  9(6).
01 IN-TBL.
   03 A       PIC  9(6) OCCURS 200000.
01 SA-TBL.
   03 SA      PIC  9(6) OCCURS 200001 DEPENDING ON N.
01 P1         PIC  9(7).
01 P2         PIC  9(7).
01 I          PIC  9(6).
01 Z          PIC  9(7).
01 GK         PIC  9(7).
01 OUT        PIC  Z(10)9.
*> 
PROCEDURE DIVISION.
  ACCEPT S.
  UNSTRING S DELIMITED BY ' '
      INTO K N.
*>
  OPEN INPUT STDIO.
  READ STDIO.
  CLOSE STDIO.
*>
  MOVE 0 TO Z GK.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO A(I)
    COMPUTE SA(I) = A(I) - Z
    MOVE A(I)            TO Z
    ADD  A(I)            TO GK
*>
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  ADD 1 TO N.
  COMPUTE SA(N) = K - GK.
  SORT SA DESCENDING KEY SA.
*>
  COMPUTE OUT = K - SA(1).
*>
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.
