The Beautiful City $$$\mathbb{S}$$$
time limit per test
3 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Since time immemorial, a delegation from our lyceum has been traveling to the beautiful city $$$\mathbb{S}$$$ to participate in a well-known olympiad. Let's dive into the year when our school team first arrived in this city. At that time, the infrastructure was not so developed, the streets were filled with intellectuals, and parts of the city were connected by boats. However, traveling by boat is not a cheap pleasure, so the local government decided to establish the construction of bridges between the islands that make up the city.

Since building a bridge that lasts forever is quite challenging, bridges in the city $$$\mathbb{S}$$$ are constructed every year. In year number $$$i$$$, starting from the first arrival of the lyceum students in this city, a new bridge is built between islands $$$u_i$$$ and $$$v_i$$$. Some bridges are so impressive that they are called important. A bridge $$$v_i \leftrightarrow u_i$$$ is considered important if the islands $$$u_i$$$ and $$$v_i$$$ become disconnected upon its removal; in other words, it is impossible to reach island number $$$u_i$$$ from $$$v_i$$$ using any bridges without using the direct bridge between them.

As time goes on, more majestic and beautiful bridges are built, and the old ones inevitably cease to be important. The government of the city $$$\mathbb{S}$$$ became interested in how many years a particular bridge was important. Since the government of the city $$$\mathbb{S}$$$ mostly deals with bureaucratic matters, this task falls to you. For each bridge, output the number of years it will be important, or $$$-1$$$ if it remains important indefinitely.

Input

The first line of input contains two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 5 \cdot 10^5$$$), the number of islands in the city $$$\mathbb{S}$$$ and the number of years during which bridges are built.

In the following $$$m$$$ lines, two integers $$$v_i, u_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$u_i \neq v_i$$$) are given, representing the numbers of the islands connected in year $$$i$$$.

It is guaranteed that after the construction of all bridges, it is possible to reach any island from any other. Also, at any moment in time, no more than one bridge directly connects any two islands.

Output

For each of the $$$m$$$ bridges, output in a new line how many years the respective bridge was important. If it ultimately remains important, output «$$$-1$$$» without quotes.

Scoring
Add. constraintsPointsReq. groupsComment
$$$n$$$$$$m$$$
$$$0$$$Tests from the statement
$$$1$$$$$$m = n - 1$$$$$$7$$$
$$$2$$$$$$n \le 300$$$$$$m \le 300$$$$$$27$$$$$$0$$$
$$$3$$$$$$n \le 1000$$$$$$m \le 1000$$$$$$26$$$$$$0,2$$$
$$$4$$$$$$n \le 1000$$$$$$40$$$$$$0,2,3$$$
$$$5$$$$$$m \le 10^5$$$$$$32$$$$$$0,2,3$$$
$$$6$$$$$$18$$$$$$0-5$$$
Examples
Input
5 5
4 5
1 2
3 4
2 3
1 4
Output
-1
3
2
1
0
Input
2 1
1 2
Output
-1