IPSC Logo

Internet Problem Solving Contest

IPSC 2001

Problem R – Strange Currency

The central bank of a certain state decided to cut down use of cash and devised a monstrous plan. They want to introduce a new set of denominations which will not allow some prices to be paid by cash. For example, if the new set consists of banknotes with face values 5, 7, 11, the sums 1,2,3,4,6,8,9 and 13 cannot be paid. Your task is to determine the largest sum that cannot be paid using banknotes from the given set. (You have an unlimited supply of banknotes of each value.)

Input file description

The input file consists of several cases. The first line of each case contains a positive integer N specifying the number of denominations in the set. The following N lines contain face values of the banknotes in the ascending order, one per line. The set never contains a banknote of value 1. There is an empty line after each test case. The last case is followed by a line containing a single 0.

Output file description

The output file contains an answer to each case in a separate line. Output 0 if arbitrarily large sums cannot be paid using the given set of banknotes.

Example

Input:
2
1000
2000

3
5
7
11

0
Output:
0
13