#C1607. Minimum Hose Uses

    ID: 44831 Type: Default 1000ms 256MiB

Minimum Hose Uses

Minimum Hose Uses

You are given a rectangular field of size \(m \times n\) represented by \(m\) strings each of length \(n\). Each character of the string is either a plant denoted by 'P' or an empty cell denoted by '.'. A hose installed along a row or a column can water all the plants in that entire row or column. Your task is to determine the minimum number of hose uses required to water all the plants in the field.

If there are no plants in the field, output \(0\). Otherwise, if hoses are installed along every row and every column that contains at least one plant, the answer is the maximum of the number of such rows and columns, i.e., \(\max(\text{rows with plants}, \text{columns with plants})\).

inputFormat

The first line contains two space-separated integers \(m\) and \(n\), representing the number of rows and the number of columns respectively. The next \(m\) lines each contain a string of length \(n\) comprised of characters 'P' and '.' indicating the field.

outputFormat

Output a single integer: the minimum number of hose uses required to water all plants. If there are no plants, output \(0\).

## sample
4 5
P..P.
..P..
P..P.
..P..
4