Problem

3 /12


Iterating over matrix elements

Theory Click to read/hide

Iterating over matrix elements

Each element of the matrix has two indices, so you need to use a nested loop to iterate over all the elements.
Usually a matrix is ​​iterated row by row: the outer loop iterates over the row indices, while the inner loop iterates over the column indices.
But if necessary, you can iterate over the matrix and the columns, then the cycles are reversed.

Problem

Write a program that calculates the sum of the elements of a matrix.

Input
The first line contains space-separated dimensions of the matrix: the number of rows N and the number of columns M (\( 1 <= N , M <= 100 \)). The following N lines contain matrix rows, each – by natural numbers separated by spaces.

Imprint
The program should output a single number – sum of matrix elements.


Examples
# Input Output
1 4 5
1 2 3 4 5
6 12 8 9 10
11 12 12 14 15
16 17 18 12 20
207