#C2749. Minimum Energy Beams

    ID: 46099 Type: Default 1000ms 256MiB

Minimum Energy Beams

Minimum Energy Beams

You are given a rectangular grid with n rows and m columns. Each cell of the grid contains one of the following characters:

  • * representing a target cell that must be destroyed,
  • # representing an obstacle cell, and
  • . representing an empty cell.

An energy beam can be fired along an entire row or an entire column. When fired, a beam destroys every target cell * in that row or column regardless of any obstacles present. However, you cannot change the direction of the beam mid-flight.

Your task is to determine the minimum number of energy beams required to destroy all target cells. Note that you must choose either firing along rows or along columns. In other words, if you fire beams along rows then you need to fire one beam for every row that contains at least one target cell, and similarly for columns. Therefore, the answer is the maximum between the number of rows that contain a target and the number of columns that contain a target.

The answer can be formulated as:

[ \text{answer} = \max\Big(#{i \mid \text{row } i \text{ contains } ''}, #{j \mid \text{column } j \text{ contains } ''}\Big) ]

</p>

inputFormat

The input is read from stdin and has the following format:

  1. The first line contains two space-separated integers n and m representing the number of rows and columns of the grid.
  2. Each of the next n lines contains a string of length m, representing a row of the grid.

outputFormat

Output a single integer to stdout — the minimum number of energy beams required to destroy all target cells.

## sample
4 5
.....
.*#..
#.*..
..*..
3

</p>