Islands

Given a grid of 8-connected islands and 4-connected seas, determine which islands enclose other islands and output island counts grouped by nesting height.

Hard8BFSGraphTreeMatrixNo attempts yetTime limit2sMemory limit128 MB

Problem

Jimin bought a map of islands and sea before leaving to search for treasure. The map is an N×M rectangle, and each cell contains either x or ..

A sea is a maximal group of . cells connected horizontally or vertically. An island is a maximal group of x cells connected horizontally, vertically, or diagonally.

An island that contains no other island has height 0. If the largest height among the islands contained in island A is K, then the height of island A is K+1.

Island A contains island B when A and B are different islands, and from any cell of island B it is impossible to move outside island A. Movement is allowed only horizontally or vertically, not diagonally.

The following map also shows island numbers for illustration.

xxx.x...xxxxx        000.0...11111
xxxx....x...x        0000....1...1
........x.x.x        ........1.4.1
..xxxxx.x...x        ..55555.1...1
..x...x.xxx.x        ..5...5.111.1
..x.x.x...x..        ..5.3.5...1..
..x...x...xxx        ..5...5...111
...xxxxxx....        ...555555....
x............        2............

There are 6 islands in this map. Five islands have height 0, namely 0 through 4, and one island has height 1, namely 5. Starting from island 3, it is impossible to leave island 5, so island 5 contains island 3. However, starting from island 4, it is possible to leave island 1, so island 1 does not contain island 4.

Given a map, output the number of islands of height 0, then height 1, and so on up to height H, where H is the greatest island height in the map.

Input

The first line contains two positive integers N and M. Each of N and M is at most 50.

The next N lines contain the island map.

Output

If there are no islands, output -1.

Otherwise, output the number of islands of height 0, height 1, ..., height H, separated by spaces. H is the greatest island height in the map.