Chain#2992

Chain

0.1 seconds
64 megabytes
Medium

You have chain pieces, where each piece consists of L_i links. You can unbend and rebend links to join separate pieces into a single chain.

Write a program that, given the number of chain pieces and the number of links in each piece L_i, determines the minimum number of links that need to be unbent and rebent to connect all pieces into one chain. The chain must not have any branches; that is, each link must be connected to exactly two other links (except for the two links at the ends, which must each be connected to only one other link).

Input

The first line contains an integer (2 \leq N \leq 10000). The second line contains integers L_i (1 \leq L_i \leq 1000000000).

Output

Output a single integer — the minimum number of links that must be unbent and rebent to connect all pieces into a single chain.

Examples

Example 1

Loading
Loading