#K47422. Distinct Elements in a Matrix

    ID: 28195 Type: Default 1000ms 256MiB

Distinct Elements in a Matrix

Distinct Elements in a Matrix

Given an N x M matrix, your task is to compute the number of distinct elements present in the matrix.

The input starts with two integers N and M which represent the number of rows and columns, respectively. Then, the matrix elements are provided in row-major order.

Formally, if \(A_{i,j}\) denotes the element in the ith row and jth column, you need to calculate the value \( \lvert\{ A_{i,j} : 1 \leq i \leq N, 1 \leq j \leq M \}\rvert \), which is the cardinality of the set of distinct elements.

inputFormat

The first line contains two integers, (N) and (M), the number of rows and columns, respectively. The following (N) lines each contain (M) space-separated integers representing the elements of the matrix.

outputFormat

Output a single integer which is the number of distinct elements in the matrix.## sample

3 3
1 2 3
4 5 6
7 8 9
9

</p>