Problem

3 /12


Iterating over matrix elements

Theory Click to read/hide

Each element of the matrix has two indexes, so you need to use a nested loop to iterate through 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 by columns, then the cycles are reversed.

Problem

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

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

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

Example.
# 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