#K75177. Crack the Safe

    ID: 34362 Type: Default 1000ms 256MiB

Crack the Safe

Crack the Safe

You are given a series of attempts to crack a 4-digit safe code. Each attempt is represented by a 4-digit number and an integer indicating the number of digits in the correct position. The objective is to determine the minimum number of attempts required to guess the correct safe code, where the safe is cracked when all 4 digits are correct.

Specifically, you are provided with \(T\) attempts. For each attempt, if the number of correct digits (in the correct position) is exactly 4, then the safe is cracked. Your task is to output the 1-indexed position of the first attempt that cracks the safe. If no attempt cracks the safe, output \(-1\).

Note: The input and output are handled through stdin and stdout respectively.

inputFormat

The first line contains an integer \(T\) (where \(T \geq 0\)), representing the number of attempts. Each of the next \(T\) lines contains two space-separated integers: the first integer is a 4-digit attempted code, and the second integer indicates the number of digits that are correct and in the correct positions.

outputFormat

Output a single integer that is the 1-indexed attempt number at which the safe is cracked (i.e., when the number of correct digits is 4). If none of the given attempts cracks the safe, output \(-1\).

## sample
3
1245 2
1235 3
1234 4
3

</p>