#K14776. Count Unique Cookies

    ID: 24210 Type: Default 1000ms 256MiB

Count Unique Cookies

Count Unique Cookies

You are given one or more grids representing a tray of cookies. Each grid has n rows and m columns. Each cell of the grid contains either a character representing a type of cookie or a dot ('.') representing an empty cell. Your task is to count the number of unique cookie types present in each tray. Cookie types are identified by any character other than the dot character.

Formally, for a given grid, let \( G \) be a set of characters with \( G = \{ tray[i][j] : tray[i][j] \neq '.' \} \). You must compute \(|G|\), the number of unique cookie types.

inputFormat

The input consists of several datasets. Each dataset begins with two integers n and m (\(1 \leq n, m \leq 1000\)) indicating the number of rows and columns, respectively. The next n lines each contain a string of length m representing a row of the tray. The input terminates with a line containing "0 0", which should not be processed.

outputFormat

For each dataset, output a single line containing the number of unique cookie types in the tray.

## sample
4 5
AAAA.
AAA..
..B..
.BBBB
3 4
C...
CDA.
CDA.
0 0
2

3

</p>