#C3899. Minimum Distinct Marble Colors After Optimal Moves

    ID: 47376 Type: Default 1000ms 256MiB

Minimum Distinct Marble Colors After Optimal Moves

Minimum Distinct Marble Colors After Optimal Moves

You are given an n by m grid, where each cell contains an integer representing the color of a marble. Despite the reference to possible moves in the narrative, the key observation is that none of these moves can reduce the number of distinct marble colors. In other words, the minimum number of distinct colors after any sequence of moves is exactly the count of distinct numbers in the initial grid.

Your task is to compute this number. Formally, given an n x m grid, output the number of unique integers present in the grid.

Input Format: The first line contains two integers n and m. Each of the following n lines contains m integers separated by spaces.

Output Format: A single integer denoting the number of distinct marble colors.

inputFormat

The input is read from stdin and consists of:

  • The first line with two space-separated integers n and m.
  • Then n lines follow, each containing m integers representing the grid rows.

outputFormat

Output the minimum number of distinct marble colors remaining after performing the optimal moves. The answer should be printed to stdout as a single integer.## sample

2 3
1 2 3
4 5 6
6

</p>