#K54192. Minimum Watering Uses

    ID: 29699 Type: Default 1000ms 256MiB

Minimum Watering Uses

Minimum Watering Uses

You are given a garden represented as an \( n \times m \) grid. Each cell in the grid contains either a '.' (empty) or a 'P' (plant). A single watering operation can water an entire row or an entire column. Your task is to determine the minimum number of watering operations needed so that all the plants are watered.

One optimal strategy is to choose either the set of rows or the set of columns that contain plants, whichever has fewer elements. Mathematically, let \( R \) be the number of rows containing at least one plant, and \( C \) be the number of columns containing at least one plant. The answer is given by: \[ \min(R, C) \]

Make sure to read the input from the standard input (stdin) and output the result to the standard output (stdout).

inputFormat

The first line contains two integers \( n \) and \( m \) separated by a space, which denote the number of rows and columns respectively.

Each of the next \( n \) lines contains a string of length \( m \), consisting only of the characters '.' and 'P', representing a row of the garden grid.

outputFormat

Output a single integer representing the minimum number of watering operations required to water all the plants.

## sample
3 3
PPP
...
...
1