时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld
题目描述
Zhou Kangyang created human civilization.
In April 11451 A.D. human built

cities on Mars. For each

, there is a merchant in the city

and a
unidirectional road from the city

to the city

.
At the beginning of each year, the merchant in the city

will go along the road to the city

.
Let's call a city start to be
bustling in the

-th year iff the

-th year is the earliest year in which there are at least

merchants in the city.
Please tell me, in which year each city start to be bustling.
输入描述:
The first line contains two integers
(
).
The second line contains
integers
(
).
输出描述:
Print
integers, the
-th of them is the number of the year in which city
start to be bustling. If a city will never be bustling, output '-1'.
示例3
输入
复制
10 2
1 6 8 5 9 9 3 8 10 5
输出
复制
-1 -1 -1 -1 1 -1 -1 1 1 2