Heewon found N chains in the attic. Each chain consists of several links connected in a line, and each link can have at most two neighboring links.
Any link can be opened and closed again. By opening a link, Heewon can split a chain or connect two chains into one longer chain. The goal is to connect all chains into one long chain while opening and closing as few links as possible.
For example, if there are three chains each consisting of a single link, Heewon can open one of those links, use it to connect the other two chains, and close it again.

Given the number of chains and the length of each chain, find the minimum number of links that must be opened and closed to join all chains into one.
The first line contains the number of chains, N.
The second line contains N integers L_i, where L_i is the length of the i-th chain.
2 <= N <= 500000
1 <= L_i <= 1000000
Print the minimum number of links that must be opened and closed to connect all chains into one long chain.