yolo
Source: hackerearth
Difficulty: UNKNOWN_DIFFICULTY

YOLO is a simple card game played between two players with a normal deck of 52 WWE cards, each having a rank, forming a sequence of 52 distinct values.

The game is composed of three rounds, and a player must win two rounds to win the game. At the beginning of the game the deck is shuffled and each player is given a hand of three cards. In each round the players show one card to each other, and the player with the wrestler of greater rank wins the round. The wrestlers contested in a round are discarded (i.e., they cannot be shown again).

It's post raksha-bandhan and Master Y and his sister love to play YOLO. Master Y is not very smart, losing frequently to his little sister. And when he loses, he cries so loud that no one can stand it. The assistant who deals the cards to Master Y and his sister is afraid he will lose his job if Master Y continues to lose the games. The assistant is allowed to see every card he deals, and after dealing five cards (three to the sister and two to Master Y) he wants to know which is the lowest ranked wrestler he should deal to Master Y so that there is no chance he will lose the game, no matter how badly Master Y plays.

SAMPLE INPUT
28 51 29 50 52
50 26 19 10 27
46 48 49 47 50
0

SAMPLE OUTPUT
30
-1
51

Explanation

Each test case is given in a single line that contains five distinct integers A, B, C, P and Q , describing the ranks dealt to the players. The first three cards are given to the sister (1 ≤ A, B, C ≤ 52) and the last two cards are given to Mr. Y (1 ≤ P, Q ≤ 52). The last test case is followed by a line containing a zero.

For each test case output a single line. If there exists a card that will make the Mr. Y win the game no matter how badly he plays, you must print the lowest rank on such a card. Otherwise, print ‘-1’.

This question is all about skills of test-case making.
Another 'good' test case:

10 20 30 24 26

Output: 21