LogiQuest

208. The Celebrity

MediumStackElimination

In a party of n people, M[i][j] = 1 means i knows j. A celebrity is known by everyone else and knows nobody. Print the celebrity's index (0-based) or -1.

Input format

Line 1: n Next n lines: n values each (0 or 1)

Output format

The celebrity, or -1.

Example 1

Input

3
0 1 0
0 0 0
0 1 0

Output

1

Example 2

Input

2
0 1
1 0

Output

-1

Constraints

1 ≤ n ≤ 1000

Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.

Loading the MyLoginn IDE…