Alien Socks
InterviewTime limit1sMemory limit1024 MB
Given counts of socks in s colors, find the smallest number of socks to draw to guarantee k socks of one color, or -1 if impossible.
Problem
An alien spaceship has landed in Bitland. The aliens were completely charmed by Bitland's fashionable socks. Because each alien has legs, they bought a huge number of socks in many different colors.
The alien Bronius keeps socks of different colors in his drawer, and he knows exactly how many socks of each color he has. Every morning Bronius pulls socks out of the drawer one at a time without looking, and he keeps going until he holds socks of the same color.
This morning Bronius is in a great hurry and wants to know the minimum number of socks he must pull out so that he is guaranteed to hold at least socks of one color.
Input
The first line contains two positive integers: Bronius's number of legs and the number of sock colors in the drawer .
The second line contains positive integers , where is the number of socks of the -th color in the drawer.
Output
Output a single positive integer — the minimum number of socks Bronius must pull out. If it is impossible for Bronius to ever collect socks of one color, output .
Constraints
- for all .