A. 每日任務 Daily Mission

Memory limit: 256 MiB Time limit: 1000 ms Input file: stdin Output file: stdout
Problem type: traditional Judging mode: text compare

Description

愛麗絲每天都在玩線上遊戲。近日,遊戲發布了新的每日任務。

每日任務中有無限個關卡,從關卡 1 開始。第 i 個關卡有一個強度為 i 的首領。對於每個關卡,玩家有 N 種武器,編號為 1 N 。第 i 種武器的力量為 P_i

玩家可以使用他/她所擁有的任何武器來對抗首領。每種武器在每個關卡中只能使用一次。若要打敗關卡 i 的首領,玩家使用的武器的力量之和必須恰好為 i

愛麗絲從關卡 1 開始。對於關卡 i ,如果愛麗絲打敗首領,她將獲得獎勵並進入關卡 i + 1 。否則,她將失去所有的獎勵。她可以在打敗任何關卡後隨時離開每日任務,從而保留她的獎勵。

愛麗絲找到了一個程序,對於給定的武器和首領的強度,它會輸出一個打敗首領的解決方案。然而,如果給定的武器實際上不可能打敗給定的強度的首領,則程序會給出錯誤的解決方案。為了最大化利潤,當遇到第一個不可能打敗的關卡時,愛麗絲會想離開並保留她所有的獎勵。請編寫一個程序來幫助愛麗絲找到第一個不可能打敗的關卡。


Alice is playing an online game every day. Recently, the game has released a new daily mission.

In the daily mission, there are infinite levels, starting from level 1 . The i -th level has a boss with strength i . For each level, the player is given N weapons numbered from 1 to N . The i -th weapon has a power of P_i .

The player can use any subset of the weapons they have to fight against the boss. Each weapon can be used only once in each level. To defeat the boss of level i , the sum of the powers of the weapons used needs to be exactly i .

Alice starts from level 1 . For level i , if Alice defeats the boss, she will get rewards and move on to level i + 1 . Otherwise, she will lose all her rewards. She can always leave the daily mission after defeating any level, thus retaining her rewards.

Alice found a program that, given the weapons and the strength of the boss, it will output a solution for defeating the boss. However, the program gives a wrong solution if the given weapons are actually impossible to defeat the boss with the given strength. To maximize the profits, Alice wants to leave and retain all her rewards when encountering the first impossible level. Please write a program to help Alice find the first impossible level.

Input

第一行輸入包含一個整數 N

第二行輸入包含 N 個整數 P_1, P_2, \dots, P_N


The first line contains an integer N .

The second line contains N integers, P_1, P_2, \dots, P_N .

Output

輸出一個整數,表示愛麗絲第一個不可能打敗的關卡。


Output exactly one integer, the first level that Alice is impossible to defeat.

Sample

Sample 1 input

3
1 2 4

Sample 1 output

8

Sample 2 input

6
2 1 1 2 6 23

Sample 2 output

13

Constraint and hint

對於全部測試數據,滿足: 1 \leq N \leq 2 \times 10^5 1 \leq P_i \leq 10^9

子任務 分數 附加限制
1 15 N \leq 20, P_1 + P_2 + \dots + P_N \leq 2000
2 20 P_1 + P_2 + \dots + P_N \leq 2000
3 P_i = 2^{i-1}
4 45 無附加限制

For all test data, 1 \leq N \leq 2 \times 10^5 , 1 \leq P_i \leq 10^9 .

Subtask Score Additional Constraints
1 15 N \leq 20, P_1 + P_2 + \dots + P_N \leq 2000
2 20 P_1 + P_2 + \dots + P_N \leq 2000
3 P_i = 2^{i-1}
4 45 No additional constraints