Clickbait

Given an ASCII map of containers joined by pipes, determine the order in which the containers fill with water starting from container 1.

Medium7SimulationGraphImplementationNo attempts yetTime limit1sMemory limit128 MB

Problem

While browsing online, Slavko ran into an ad showing a system of containers and pipes with the message "If container 1 starts filling up with water, work out the order in which the containers get filled up." One such system is drawn below.

The system has K containers numbered from 1 to K, and a matrix of characters with N rows and M columns describes it. Every container is a rectangle, and the outlines of the containers and the pipes use these characters:

  • - for a horizontal part of an outline,
  • | for a vertical part of an outline,
  • + for a spot where a horizontal part meets a vertical part.

The spot where a container meets a pipe is an exception: there the container outline wins.

Somewhere inside each container there is a string of digits that gives the number of that container, and every other cell of the matrix holds . (a dot).

Every container except container 1 has exactly one supply pipe, and that pipe enters the container through its upper side. Container 1 has no supply pipe.

A container can have several discharge pipes or none at all, and a discharge pipe leaves the container through one of its lateral sides. Within one container, the spots where discharge pipes leave lie in distinct rows of the matrix.

A pipe connects two containers directly. A pipe is never split, several pipes are never merged into one, and no two pipes cross. Going from the source container to the destination container, a pipe always descends to the next row or stays in the same row, so it never returns to the previous row and the water flows freely from one container into another.

Water keeps entering a container until that container is full. Once the water level reaches the height of a discharge pipe, water flows through that pipe until the container it leads into is full.

Determine the order in which the containers fill up.

Please note

  • In the test data, exactly one of the two cells left and right of a + character holds -, exactly one of the two cells above and below it holds |, and all the other cells next to it in the four directions hold . (a dot).
  • The only cells where a pipe sits next to a container outline are the cells where the pipe enters or leaves that container. A pipe never runs right alongside a container. The entrance of a supply pipe is the | character above a container, and the exit of a discharge pipe is the - character just outside a lateral side of a container.

Input

The first line contains the matrix dimensions N and M (1N,M10001 \le N, M \le 1000).

Each of the next N lines contains M characters describing the container system.

Output

Print K lines. The i-th line holds the number of the container that fills up i-th. An answer always exists and it is unique.

Note

The first example works out as follows.

Container 1 starts filling up with water.

The water level in container 1 rises until it reaches the height of the pipe leading to container 2. Water flows through that pipe until container 2 is full.

The water level in container 1 then keeps rising until it reaches the height of the pipe leading to container 3, and container 3 fills up next.

Finally the water level in container 1 keeps rising and container 1 fills up.