#K72487. Sum of Unique Integers

    ID: 33764 Type: Default 1000ms 256MiB

Sum of Unique Integers

Sum of Unique Integers

You are given a grid of integers with N rows and M columns. Your task is to calculate the sum of all unique integers present in the grid.

Formally, let the grid be represented as a matrix. Define the set of unique integers as \(U = \{a_{ij} : 1 \leq i \leq N,\ 1 \leq j \leq M\}\). You need to compute the sum \(\sum_{x \in U} x\).

inputFormat

The first line of input contains two integers N and M representing the number of rows and columns respectively. Each of the next N lines contains M space-separated integers denoting the grid values.

outputFormat

Output a single integer which is the sum of all unique integers in the grid.

## sample
3 3
1 2 3
4 5 6
1 2 3
21