#000037

bankomati

In the new era of electronic wonders, automated teller machines (ATMs) are becoming a common thing. Banks want their clients to remain at the ATMs for as short a time as possible so that more people could use them. For this reason they want to give money to their clients in as few bills as possible. However, ATMs were set up by lazy programmers who used the simplest algorithm. Each time the ATMs first give the largest bill not larger than the complete sum to be given and then they give the remaining amount in smaller bills. For example, in a system with bills of 1, 7 and 10 dollars the sum of 14 dollars will be paid off with 1 bill of 10 and 4 bills of 1 dollar, which gives 5 bills altogether. This is not in compliance with the bank’s policy, because 14 dollars could be paid off with only 2 bills of 7 dollars.


Your task is to write a program which will, for a given system of bills (which always contains a 1 dollar bill), find the smallest amount that can be paid off with fewer bills than the ATM would give.


InputThe first line of the standard input contains the number N, which represents the number of bills in the system (1 <= N <= 50). In the second line there are N different natural numbers, which represent the values of the bills in the system. Each bill is not larger than 500000, and one of them is a 1 dollar bill.

OutputTo the standard output write the number M, where M represents the smallest amount the ATMs do not pay off with the smallest number of bills. If they always pay off the sum with the smallest number of bills, write 0.

Input:
3
1 7 10
Output
14

Submit solution

Coming later

The grading service will be connected in a later migration step. You can inspect the task and your previous results now.