eolymp
Competitions

Introduction Contest

White hats

There is a number of people in a room, and each of them wears a hat which is either black or white. Every person counts the number of other people wearing white hats. Find the total number of people wearing white hats, or tell that input data doesn't correspond to a valid situation.

Input

Each line gives one test. Each line contains the sequence of numbers a1, a2, ..., an, where ai contains the number of hats counted by i - th man.

Output

For each test print on a separate line the number of people in white hats or -1 if input data doesn't correspond to a valid situation.

Time limit 1 second
Memory limit 128 MiB
Input example #1
2 1 1
2 2 2
10 10
Output example #1
2
3
-1