Problem

3 /12


Iterating over matrix elements

Theory Click to read/hide

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 the dimensions of the matrix separated by a space: the number of rows and the 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.

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